简体   繁体   English

在Linux中配置ODBC驱动程序

[英]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 我已经按照此链接中的所有步骤进行操作: 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 [unixODBC] [驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序

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 然后,当我开始进行更多研究时,我发现了这一点: 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. 现在,它说要修改odbc.ini文件以包括服务器和数据库名称。 But if I'm trying to connect to multiple servers at the same time, how should I configure odbc.ini file in this case? 但是,如果尝试同时连接到多个服务器,在这种情况下应如何配置odbc.ini文件?

Also - in my database connection string, should I enter the driver name as {SQL Server} or {FreeTDS}? 另外-在我的数据库连接字符串中,应该输入驱动程序名称为{SQL Server}还是{FreeTDS}?

Here's an example set up with FreeTDS, unixODBC, and friends: 这是使用FreeTDS,unixODBC和好友设置的示例:

freetds.conf: 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: 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: 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. 上面的Driver =位置可能有所不同,具体取决于您的FreeTDS发行版。

pyodbc connect, DSN free: pyodbc connect,免费提供DSN:

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. 您必须更新TDS版本以匹配您正在运行的SQL Server版本和您正在运行的免费TDS版本。 Version 0.95 supports TDS Version 7.3. 0.95版支持TDS 7.3版。
  • TDS Version 7.3 will work with MS SQL Server 2008 and above. TDS 7.3版可与MS SQL Server 2008及更高版本一起使用。
  • Use TDS Version 7.2 for MS SQL Server 2005. 使用MS SQL Server 2005的TDS版本7.2。

See here for more: 看到这里更多:

https://msdn.microsoft.com/en-us/library/dd339982.aspx 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? 如果尝试同时连接到多个服务器,在这种情况下应如何配置odbc.ini文件?

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. 如果要连接到多台服务器,则需要为每台服务器创建一个单独的DSN条目,并使用多个pyodbc connection对象。 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. 或者,或者在其中一个SQL Server实例上设置“链接服务器”,以便您可以通过相同的pyodbc连接访问两者。

in my database connection string, should I enter the driver name as {SQL Server} or {FreeTDS}? 在数据库连接字符串中,我应该输入驱动程序名称为{SQL Server}还是{FreeTDS}?

If you are editing "odbc.ini" then you are creating DSN entries. 如果您正在编辑“ odbc.ini”,那么您正在创建DSN条目。 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". 您将在连接字符串中使用DSN名称,pyodbc将从“ odbc.ini”中的相应条目中获取详细信息(服务器名称,数据库名称)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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