为什么一个ODBC连接工作,第二个不工作?

问题描述:

我在Ubuntu 14.04上使用ODBC和FreeTDS。我们现在有三台服务器可能在同一时间运行数据库(一次只能运行一台)。为什么一个ODBC连接工作,第二个不工作?

我尝试将第二台服务器添加到我的freetds.conf和odbc.ini文件中,但即使指定了相同的IP地址进行测试,它也不会连接。

odbc.ini文件

[Default] 
Driver=NewFreeTDS 

[MKMSDef] 
Driver=NewFreeTDS 
serverName=MKMSDefault 

[MKMSSecond] 
Driver=NewFreeTDS 
serverName=MKMSSecond 

[VP] 
Driver=NewFreeTDS 
ServerName=VirtualPrinter 

freetds.conf文件

[global] 
     tds version = 4.2 

     # Whether to write a TDSDUMP file for diagnostic purposes 
     # (setting this to /tmp is insecure on a multi-user system) 
     dump file = /tmp/freetds.log 
     debug flags = 0xffff 

     # Command and connection timeouts 
     timeout = 10 
     connect timeout = 10 

     # If you get out-of-memory errors, it may mean that your client 
     # is trying to allocate a huge buffer for a TEXT field. 
     # Try setting 'text size' to a more reasonable limit 
     text size = 64512 

[MKMSSecond] 
     host = 10.1.10.71 
     database = MKMSDefault 
     port = 2638 

[MKMSDefault] 
     host = 10.1.10.71 
     database = MKMSDefault 
     port = 2638 

[VirtualPrinter] 
     host = 10.1.10.22 
     database = VP 
     port = 2638 

isql命令MKMSDef用户通成功连接 isql命令MKMSSecond用户通失败

我什么也看不见了之间的不同两个导致这一点。

编辑 经过一些进一步的测试。它似乎没有读取所有的信息来知道要连接到什么。无论在odbc.ini中指定为“ServerName”,都必须是数据库名称。它也需要在freetds.conf中定义,但只有IP和端口需要在那里。

如果我连接到仅运行一个数据库的计算机,则servername无关紧要。

这似乎不是正确的行为。

正如你已经部分想到的,如果你保持你的命名一致,简单,并以相同的顺序,它会容易得多。这里有一个例子:

freetds.conf

[bob] 
host = bob.myserver.com 
port = 1433 
tds version = 7.2 

[fred] 
host = fred.myserver.com 
port = 1433 
tds version = 7.2 

[joe] 
host = joe.myserver.com 
port = 1433 
tds version = 7.2 

odbc.ini

[bob] 
Driver = FreeTDS 
Server =bob.myserver.com 
Port = 1433 
TDS_Version = 7.2 

[fred] 
Driver = FreeTDS 
Server = fred.myserver.com 
Port = 1433 
TDS_Version = 7.2 

[joe] 
Driver = FreeTDS 
Server = joe.myserver.com 
Port = 1433 
TDS_Version = 7.2 

如果你已经清理,但仍然遇到问题,请包括isql -v信息,以便我们可以看到什么错误正在产生的。