Linux freeTDS 不使用其配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13066716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
freeTDS not using its config
提问by khartvin
I've decided to use FreeTDS driver and unixODBC to manage the PDO connection between my LAMP-based app with a remote MsSQL database. unfortunately it appears that the driver doesn't read the freetds.conf file, nor the environmental variables set either directly via server's CLI or specified in php file by putenv() function.
我决定使用 FreeTDS 驱动程序和 unixODBC 来管理基于 LAMP 的应用程序与远程 MsSQL 数据库之间的 PDO 连接。不幸的是,驱动程序似乎没有读取 freetds.conf 文件,也没有直接通过服务器的 CLI 设置或通过 putenv() 函数在 php 文件中指定的环境变量。
now some data:
现在一些数据:
- as I ping the server - no packets are lost.
- as I telnet the server on 1433 port - the connection is established
as I use the command
TDSVER=7.0 tsql -H >IP< -p 1433 -U username
I am prompted to enter password and connection is established.
without the TDSVER preceding the command - the connection fails with such a message:
Error 20017 (severity 9): Unexpected EOF from the server OS error 115, "Operation now in progress" Error 20002 (severity 9): Adaptive Server connection failed There was a problem connecting to the server
the tsql -C commands echos such an output:
Compile-time settings (established with the "configure" script) Version: freetds v0.91 freetds.conf directory: /usr/local/etc MS db-lib source compatibility: yes Sybase binary compatibility: no Thread safety: yes iconv library: yes TDS version: 5.0 iODBC: no unixodbc: yes SSPI "trusted" logins: no Kerberos: no
freetds.conf in the location given above has this entry:
[MSSQL] host = >IP< port = 1433 tds version = 7.0
the ISQL also fails:
isql -v MSSQL [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source [01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed [ISQL]ERROR: Could not SQLConnect
my odbc.ini :
[MSSQL] Description = MS SQL Server Driver = FreeTDS TDS_Version = 7.0 Server = >IP< UID = username PWD = password ReadOnly = No Port = 1433
- 当我 ping 服务器时 - 没有数据包丢失。
- 当我在 1433 端口上 telnet 服务器时 - 连接已建立
当我使用命令时
TDSVER=7.0 tsql -H >IP< -p 1433 -U username
系统提示我输入密码并建立连接。
如果命令前面没有 TDSVER - 连接失败并显示以下消息:
Error 20017 (severity 9): Unexpected EOF from the server OS error 115, "Operation now in progress" Error 20002 (severity 9): Adaptive Server connection failed There was a problem connecting to the server
tsql -C 命令回显这样的输出:
Compile-time settings (established with the "configure" script) Version: freetds v0.91 freetds.conf directory: /usr/local/etc MS db-lib source compatibility: yes Sybase binary compatibility: no Thread safety: yes iconv library: yes TDS version: 5.0 iODBC: no unixodbc: yes SSPI "trusted" logins: no Kerberos: no
上面给出的位置中的 freetds.conf 具有以下条目:
[MSSQL] host = >IP< port = 1433 tds version = 7.0
ISQL 也失败:
isql -v MSSQL [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source [01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed [ISQL]ERROR: Could not SQLConnect
我的 odbc.ini :
[MSSQL] Description = MS SQL Server Driver = FreeTDS TDS_Version = 7.0 Server = >IP< UID = username PWD = password ReadOnly = No Port = 1433
I suppose the solution is really simple, but i'm just too stupid to find it...
我想解决方案真的很简单,但我太笨了找不到它......
采纳答案by Max Bolingbroke
I spent a long time today debugging a similar problem. I had set "TDS version" in freetds.conf but it was not being used in my ODBC connection. After reading the freetds source code (connectparams.c:odbc_parse_connect_string) I discovered that:
我今天花了很长时间调试一个类似的问题。我在 freetds.conf 中设置了“TDS 版本”,但它没有在我的 ODBC 连接中使用。阅读 freetds 源代码(connectparams.c:odbc_parse_connect_string)后,我发现:
- If your connection string uses "SERVER=" then both freetds.conf and odbc.ini are ignored
- If your connection string uses "SERVERNAME=" then the settings in the appropriate freetds.conf server are used
- If your connection string uses "DSN=" then the settings in the appropriate odbc.ini DSN are used
- 如果您的连接字符串使用“SERVER=”,则 freetds.conf 和 odbc.ini 都将被忽略
- 如果您的连接字符串使用“SERVERNAME=”,则使用相应 freetds.conf 服务器中的设置
- 如果您的连接字符串使用“DSN=”,则使用相应 odbc.ini DSN 中的设置
odbcinst.ini is a red herring. FreeTDS never checks that for settings.
odbcinst.ini 是一个红鲱鱼。FreeTDS 从不检查设置。
The settings you specify in the connection stringare always respected. It also always respects the environment variables like TDSVER.
您在连接字符串中指定的设置始终受到尊重。它还始终尊重 TDSVER 等环境变量。
回答by Andomar
Instead of connecting to an IP, try to connect to the name of the configuration section? For example:
而不是连接到IP,尝试连接到配置部分的名称?例如:
isql -v MSSQL
回答by Benny Hill
My gut instinct is you need to change your tds version = 7.0to tds version = 8.0in your freetds.conf and odbc.ini files AND you need something in your odbcinst.ini file. Here's what I've got working on an Ubuntu 12.04 server talking to a remote MSSQL server:
我的直觉是你需要在你的 freetds.conf 和 odbc.ini 文件中将你的tds version = 7.0更改为tds version = 8.0并且你需要在你的 odbcinst.ini 文件中添加一些东西。这是我在 Ubuntu 12.04 服务器上与远程 MSSQL 服务器通信的工作:
freetds.conf
freetds.conf
# Define a connection to the MSSQL server.
[mssql]
host = myserver
port = 1433
tds version = 8.0
odbc.ini
数据库配置文件
# Define a connection to the MSSQL server.
# The Description can be whatever we want it to be.
# The Driver value must match what we have defined in /etc/odbcinst.ini
# The Database name must be the name of the database this connection will connect to.
# The ServerName is the name we defined in /etc/freetds/freetds.conf
# The TDS_Version should match what we defined in /etc/freetds/freetds.conf
[mssql]
Description = MSSQL Server
Driver = freetds
Database = MyDB
ServerName = myserver
TDS_Version = 8.0
odbcinst.ini
odbcinst.ini
# Define where to find the driver for the Free TDS connections.
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
回答by jmsq
I experienced this exact same problem, but my config was already correctly set up. The problem was that the TDS versions that freetds.conf recognizes has changed in newer versions, but apparently the old versions still work in the TDSVER environment variable. Once I set the version in the config files to 7.1 rather than 8.0 everything started working.
我遇到了完全相同的问题,但我的配置已经正确设置。问题是 freetds.conf 识别的 TDS 版本在新版本中发生了变化,但显然旧版本仍然在 TDSVER 环境变量中工作。一旦我将配置文件中的版本设置为 7.1 而不是 8.0,一切都开始工作了。
回答by SCDomingos
The initial TDSVER=7.0
issue was resolved by adding the following at the end of my odbc.ini
file:
TDSVER=7.0
通过在我的odbc.ini
文件末尾添加以下内容解决了最初的问题:
[Default]
Driver=/usr/local/lib/libtdsodbc.so