I trid the following code,
import pyodbc try: pyodbc.connect(\'DRIVER={%s};SERVER=%s;DATABASE=%s;UID=%s;PWD=%s\' % (driver, server, database, uid, passwo
this will give you more clear and readable error message when connecting to mssql using myodbc:
try: cnxn = pyodbc.connect(...) except pyodbc.Error as ex: sqlstate = ex.args[1] sqlstate = sqlstate.split(".") print(sqlstate[-3])