我有一个Ubuntu12.04服务器,我正在尝试建立到MSSQL数据库的连接。
我已经设法使用tsqlisql连接,但是osql不起作用,使用pdo连接php也不起作用。我会尽力提供尽可能多的信息,如果你需要更多,只要让我知道,我会编辑。
freetds.conf版本:

[MSSQL]
  host = TPSACC
  port = 54488
  tds version = 8.0

odbc.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

ODBCinst.ini号:
[FreeTDS]
Description = ODBC for Microsoft SQL
Driver      = /usr/local/lib/libtdsodbc.so
UsageCount  = 1
Threading   = 2

~>ISQL MSSQL SA过程
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

~>tsql-s mssql-u'sa'-p'pass'
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>

~>OSQL-S MSSQL-U SA-P过程
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"

在php中,我有:
$conn = new PDO ("dblib:host=TPSACC;dbname=PRODUCTION","$username","$pw");

…或..
$conn = new PDO ("dblib:host=TPSACC;port=54488;dbname=PRODUCTION","$username","$pw");

它们都返回这个错误:
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (severity 9)

我在这里被困了几天,不太明白为什么只有一半的网络能正常工作。
非常感谢您的帮助,谢谢!
编辑:这和那个问题不同,我在评论中解释过,但会在这里转载:
对于那个问题是端口从1433改变了。我的也被更改了,我修复了这个问题,端口现在是54488,自从这个更改以来,tsql和isql一直在工作。但是,它仍然不能解决osql和php问题。

最佳答案

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的正确位置吗?当我用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更好地保持一致性。如果你需要检查参考,我有一个流浪箱与完整的配置,这里提供的例子:https://github.com/FlipperPA/django-python3-vagrant/好运!

07-26 05:04