我目前正在设置从Linux机箱到Microsoft SQL服务器的连接。我在Linux机器上安装了FreeTDS和pyodbc。
我已设置以下文件: /etc/freetds/freetds.conf
[sqlserver]
host = <ip address>
port = 1433
tds version = 8.0
client charset = UTF-8
〜/ .odbc.ini的
[sqlserver]
Description = FreeTDS MSSQL
Driver = FreeTDS
Servername = <same ip as above>
Database = Reports
TDS_Version = 8.0
/etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS MSSQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Driver64 = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Setup64 = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount = 1
CPTimeout =
CPTimeToLive =
DisableGetFunctions =
DontDLCLose =
ExFetchMapping =
Threading =
FakeUnicode =
IconvEncoding =
Trace =
TraceFile =
TraceLibrary =
当我尝试运行tsql -S sqlserver -U username -P密码时,出现以下错误:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Msg 18452 (severity 14, state 1) from SYMPLECTIC03 Line 1:
"Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
我还尝试使用pyodbc连接,在以下脚本中:
import pyodbc
try:
cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER=same_ip_as_above;DATABASE=Reports;UID=myusername;PWD=mypassword')
except pyodbc.Error, err:
print err
会打印以下错误:
('001', '[001] [nxDC[reD]SLSre]nbet onc odt ore (0) (SQLDriverConnect)')
不完全是最有用的错误消息。
尝试连接时有什么问题吗?
作为旁注,我们的数据库需要Windows身份验证,而不是集成。 我可以telnet连接到主机,所以这也不是问题。
答案 0 :(得分:3)
安装程序看起来很好。我有一个类似的工作,在服务器升级到NTLMv2后中断了。在测试tsql
时,这会出现“ ...不受信任的域 ...”错误。 * detail here
我只需在use ntlmv2 = yes
规范中加入freetds.conf
。
答案 1 :(得分:1)
使用Windows身份验证可能很棘手......而且非常难看。最佳实践:
您还需要更改此行以包含TDS版本:
cnxn = pyodbc.connect(&#39; DRIVER = FreeTDS; SERVER = same_ip_as_above; DATABASE = Reports; UID = myusername; PWD = mypassword; TDS_Version = 7.2;&#39;)
此致
-Tim