简体   繁体   中英

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}?

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.

if I'm trying to connect to multiple servers at the same time, how should I configure odbc.ini file in this case?

If you want to connect to more than one server you will need to create a separate DSN entry for each one and use more than one pyodbc connection object. Either that, or set up a "Linked Server" on one of the SQL Server instances so you can access both through the same pyodbc connection.

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

If you are editing "odbc.ini" then you are creating DSN entries. You would use the DSN name in your connection string, and pyodbc would get the details (server name, database name) from the corresponding entry in "odbc.ini".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM