pyodbc.OperationalError: ('HYT00', u'[HYT00] [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

Viewed 13982

Using the SQL Server Management Studio (SSMS) Express, I can find the database and connect without problems.

But when I use pyodbc to connect to the same server using:

    import pyodbc
    Server = r"xxxER\xxxSQLSERV"
    db = "xxxDB"
    user = "xxx"
    password = "xxxx"
    conn = pyodbc.connect('DRIVER={SQL Server};SERVER='+server + ';DATABASE=' + db +';UID=' + user + ';PWD=' + password)

By Using Pyhton in my local i am able to connect but when i am trying in linux server getting below error

pyodbc.OperationalError: ('HYT00', u'[HYT00] [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

i tried with ODBC Driver 17 for SQL Server too but facing the same issue.Can any one please suggest me on this.

6 Answers

Microsoft's SQL Server ODBC drivers for Linux are unable to resolve instance names. You can use the free sqlserverport module to get the corresponding port number and use that to connect.

Try removing the instance from server and set it as

Server = "xxxER"

or if you have a port number append it as

Server = "xxxER,portNo"

I have this problem and solved my problem in here. Just add version.

conn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server + ';DATABASE=' + db +';UID=' + user + ';PWD=' + password)

If not work change version 17 to 13 if not to 11 . List versions of ODBC.

Check your mssql network config, my problem was there.

Enable port 1433 for all IPs.

Now is working with IP and host name.

I am using SSH Tunnel with remote server port forward to localhost,1433. This pyodbc connection intermittently fails if using the approach:

cnxn = pyodbc.connect('driver={ODBC Driver 17 for SQL Server};Server=localhost, 1433;'...

Replacing localhost with 127.0.0.1 seems to be working all the time

cnxn = pyodbc.connect('driver={ODBC Driver 17 for SQL Server};Server=127.0.0.1, 1433;'

Incidentally also did same using Ruby and FreeTDS, and Localhost,1433 worked all the time.. Must be something inside the pyodbc package or their approach that sometimes drop some info to make the DBMS on server fail to respond/timeout

This worked for me:

mssql://DRIVER={ODBC Driver 17 for SQL Server};SERVER={server_address,PORT};DATABASE=<my_database>;UID=<my_username>;PWD=<my_password>
Related