配置 FreeTDS 以连接到 MS SQL

配置 FreeTDS 以连接到 MS SQL

我根据此页面尝试了几种不同的配置选项(http://enlook.wordpress.com/2013/05/02/error-sql-error-unixodbcdriver-managerdata-source-name-not-found-and-no-default-driver-specified/#comment-2783

还有一个非常类似的帖子使用 freetds 和 unixodbc 连接 MS SQL:isql - 未指定默认驱动程序但是,当我尝试使用 isql 测试连接时,我继续收到“[IM002][unixODBC][驱动程序管理器]未找到数据源名称,且未指定默认驱动程序 [ISQL]ERROR:无法 SQLConnect”。

我正在运行 Ubuntu 12.04 LTS 服务器并通过 安装了 freeTDS apt-get

结果odbcinst -q -d

@cabana:/etc# odbcinst -q -d
[TDSDRIVER]

odbcinst -q- s 的结果

@cabana:/etc# odbcinst -q -s
[MSSQL]
[SQL01]

tds.驱动程序.模板:

@cabana:/etc# cat tds.driver.template
[TDSDRIVER]
Description = FreeTDS driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
FileUsage = 1
UsageCount =1

tds.数据源.模板:

@cabana:/etc# cat tds.datasource.template
[SQL01]
Driver = TDSDRIVER # name that we specified in the driver file
Description = MSSQL ODBC Driver
Trace = No
TraceFile = /var/log/freetds.log
Server = 10.0.0.200 # this name specified in the freetds.conf
Port = 1433
Database = MyDatabase
TDS_Version = 8.0

freetds.conf:

@cabana:/etc# cat freetds.conf
[global]
tds version = 8.0
[MICROSOFT]
host = 10.0.0.200
port = 1433
tds version = 8.0

odbc.ini:

@cabana:/etc# cat odbc.ini
[MSSQL]
Driver = FreeTDS # name that we specified in the driver file
Description = MSSQL ODBC Driver
Trace = No
TraceFile = /var/log/freetds.log
Servername = 10.0.0.200 # this name specified in the freetds.conf
Port = 1433
Database = MyDatabase
TDS_Version = 7.0

[SQL01]
Driver = TDSDRIVER # name that we specified in the driver file
Description = MSSQL ODBC Driver
Trace = No
TraceFile = /var/log/freetds.log
Server = 10.0.0.200 # this name specified in the freetds.conf
Port = 1433
Database = MyDatabase
TDS_Version = 8.0

odbcinst.ini:

@cabana:/etc# cat odbcinst.ini
[TDSDRIVER]
Description = FreeTDS driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
FileUsage = 1
UsageCount = 2

tsql 未安装,因此使用 isql 测试时我得到以下结果:

@cabana:/etc# isql -v SQL01 user pass
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

我究竟做错了什么?

答案1

我刚刚遇到了类似的问题:MS SQL 的问题可能是端口或实例。我建议您运行:

tsql -LH [SERVER_IP_ADR]

获取端口号并更新freetds.conf

如果您的服务器正在使用实例(即实例名称与 MSSQLSERVER 不同),您也可以尝试 /etc/odbc.ini使用以下命令进行更新:

Server  = [SERVER_IP_ADR]\\[INSTANCE_NAME]

它对我有用。

用相应的值替换方括号。

相关内容