Search code examples
sql-serverlinuxfreetdsunixodbcpypyodbc

Configure ODBC drivers in Linux


I've followed all the steps from this link: https://code.google.com/p/pypyodbc/wiki/Linux_ODBC_in_3_steps

But I'm still getting this error:

[unixODBC][Driver Manager] Data source name not found, and no default driver specified

Then when I started researching more, I found this: https://askubuntu.com/questions/167491/connecting-ms-sql-using-freetds-and-unixodbc-isql-no-default-driver-specified

Now it says to modify odbc.ini file to include the server and database name. But if I'm trying to connect to multiple servers at the same time, how should I configure odbc.ini file in this case?

Also - in my database connection string, should I enter the driver name as {SQL Server} or {FreeTDS}?


Solution

  • Here's an example set up with FreeTDS, unixODBC, and friends:

    freetds.conf:

    [server1]
            host = one.server.com
            port = 1433
            tds version = 7.3
    
    [server2]
            host = two.server.com
            port = 1433
            tds version = 7.3
    

    odbc.ini:

    [server1]
    Driver = FreeTDS
    Server = one.server.com
    Port = 1433
    TDS_Version = 7.3
    
    [server2]
    Driver = FreeTDS
    Server = two.server.com
    Port = 1433
    TDS_Version = 7.3
    

    odbcinst.ini:

    [FreeTDS]
    Description = FreeTDS with Protocol up to 7.3
    Driver = /usr/lib64/libtdsodbc.so.0
    

    The Driver = location may differ above, depending on your distro of FreeTDS.

    pyodbc connect, DSN free:

    DRIVER={FreeTDS};SERVER=one.server.com;PORT=1433;DATABASE=dbname;UID=dbuser;PWD=dbpassword;TDS_Version=7.3;
    

    A few notes:

    • You'll have to update the TDS version to match the version of SQL Server you are running and the Free TDS version you are running. Version 0.95 supports TDS Version 7.3.
    • TDS Version 7.3 will work with MS SQL Server 2008 and above.
    • Use TDS Version 7.2 for MS SQL Server 2005.

    See here for more:

    https://msdn.microsoft.com/en-us/library/dd339982.aspx

    Good luck.