I am unable to make a connection to the SQL server from Unix using python.
I will not be able to replace the driver from ODBC Driver 17 for SQL Server to ODBC Driver 13 for SQL Server as explained in Pyodbc: Login Timeout Error due to other dependencies.
Can somebody please suggest an alternative?
CODE:
import sqlalchemy as sa
from urllib import parse as db_parse
from sqlalchemy import event
params = db_parse.quote_plus(r"DRIVER={ODBC Driver 17 for SQL Server};SERVER='server,port';DATABASE=DB_NAME;username=USER_ID;password=PWD;Trusted_Connection=yes")
engine = sa.create_engine('mssql+pyodbc:///?odbc_connect={}'.format(params))
connection = engine.connect()
ERROR:
sqlalchemy.exc.OperationalError: (pyodbc.OperationalError) ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)') (Background on this error at: http://sqlalche.me/e/e3q8)
Trusted_Connection=yes
means Windows Authentication which can't be used on Linux. You can't use that and a SQL login in the same connection string. What does the actual connection string look like? There could be a real timeout error, or it could be a problem caused by an incorrect value. For exampleSERVER='server,port'
is wrong, the server name and port don't need quoting