我有一台Ubuntu 12.04服务器,我试图建立与MSSQL数据库的连接。
我已设法使用stdin, stdout, stderr = channel.exec_command("python myScript.py")
stdin.close()
for line in iter(lambda: stdout.readline(2048), ""):
print(line, end="")
和tsql
进行连接,但isql
无法正常工作,并且使用PDO与PHP连接也无法正常工作。我会尝试提供尽可能多的信息,如果你需要更多信息,请告诉我,我会编辑。
freetds.conf :
osql
ODBC.INI :
[MSSQL]
host = TPSACC
port = 54488
tds version = 8.0
ODBCINST.INI :
[MSSQL]
Description = MS SQL connection to PRODUCTION database
Driver = FreeTDS
Database = PRODUCTION
Server = TPSACC
UserName = sa
Password = pass
Trace = No
TDS_Version = 8.0
Port = 54488
〜> isql MSSQL sa pass
[FreeTDS]
Description = ODBC for Microsoft SQL
Driver = /usr/local/lib/libtdsodbc.so
UsageCount = 1
Threading = 2
〜> tsql -S MSSQL -U' sa' -P'通过'
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
〜> osql -S MSSQL -U sa -P pass
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
在PHP中我有:
checking shared odbc libraries linked to isql for default directories...
strings: '': No such file
trying /tmp/sql ... no
trying /tmp/sql ... no
trying /etc ... OK
checking odbc.ini files
reading /home/toolplas/.odbc.ini
[MSSQL] not found in /home/toolplas/.odbc.ini
reading /etc/odbc.ini
[MSSQL] found in /etc/odbc.ini
found this section:
[MSSQL]
Description = MS SQL connection to PRODUCTION database
Driver = FreeTDS
Database = PRODUCTION
Server = TPSACC
UserName = sa
Password = pass
Trace = No
TDS_Version = 8.0
Port = 54488
looking for driver for DSN [MSSQL] in /etc/odbc.ini
found driver line: " Driver = FreeTDS"
driver "FreeTDS" found for [MSSQL] in odbc.ini
found driver named "FreeTDS"
"FreeTDS" is not an executable file
looking for entry named [FreeTDS] in /etc/odbcinst.ini
found driver line: " Driver = /usr/local/lib/libtdsodbc.so"
found driver /usr/local/lib/libtdsodbc.so for [FreeTDS] in odbcinst.ini
/usr/local/lib/libtdsodbc.so is an executable file
"Server" found, not using freetds.conf
Server is "TPSACC"
osql: no IP address found for "TPSACC"
.. ..或
$conn = new PDO ("dblib:host=TPSACC;dbname=PRODUCTION","$username","$pw");
他们都返回了这个错误:
$conn = new PDO ("dblib:host=TPSACC;port=54488;dbname=PRODUCTION","$username","$pw");
我已经被困在这里几天了,并且无法弄清楚为什么只有一半的连接确实有效..
非常感谢任何和所有帮助,谢谢!
编辑:与问题不同,我在评论中解释但会在此处重新发布:对于那个问题是端口是从1433更改的。我的也被更改了,我修复了,端口现在是54488,因为更改tsql和isql一直在工作。但是,它仍然没有解决osql和PHP问题。
答案 0 :(得分:0)
osql
在你的配置中窒息。 osql
是一个调试实用程序,它只是检查您的配置,然后传递给unixODBC的isql
以连接(http://linux.die.net/man/1/osql)。试试你的odbc.ini:
[MSSQL]
Driver = FreeTDS
Description = MS SQL connection to PRODUCTION database
Server = tpsacc.yourfulldomain.com
Port = 54488
TDS_Version = 7.2
Database = PRODUCTION
UserName = sa
Password = pass
Trace = No
另外,你确定它是libtdsodbc.so的正确位置吗?当我使用Ubuntu 14 x64(utopic)安装freetds-dev时,它将安装到/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so;例如odbcinst.ini:
[FreeTDS]
Description = v0.91 with protocol v7.2
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
为了更好的衡量,我使用的典型freetds.conf:
# A typical Microsoft server
[MSSQL]
host = tpsacc.yourfulldomain.com
port = 54488
tds version = 7.2
FreeTDS仅支持大多数语言的TDS 7.2版。在使用" 8.0"不应该破坏任何东西,使用7.2更好的一致性。如果你需要检查参考,我有一个Vagrant盒子,里面有完整的配置,例如:https://github.com/FlipperPA/django-python3-vagrant/祝你好运!