What's causing 'unable to connect to data source' for pyodbc?

前端 未结 13 2203
北荒
北荒 2020-12-28 14:34

I\'m trying to connect to an MSSQL database from python on Linux (SLES).

I have installed pyodbc and Free TDS. From the command line:

tsql -H server          


        
13条回答
  •  -上瘾入骨i
    2020-12-28 15:20

    I had the same problem and I found out that it was missing the TDS_Version parameter in the call to connect(). The following code works for me to connect to an instance of MS SQL Server 2008:

    import pyodbc
    
    driver = '/opt/local/lib/libtdsodbc.so' # Change this to where FreeTDS installed the driver libaray!
    
    conn = pyodbc.connect(
        driver = driver,
        TDS_Version = '7.2', # Use for
        server = '',
        port = 1433,
        database = '',
        uid = '',
        pwd = '')
    

提交回复
热议问题