【问题标题】:SQLSTATE[01002] Adaptive Server connection failed (severity 9) error on Ubuntu Linux VPSSQLSTATE[01002] Ubuntu Linux VPS 上的 Adaptive Server 连接失败(严重性 9)错误
【发布时间】:2017-01-09 05:47:42
【问题描述】:

我正在尝试通过我的 php 脚本连接到 Azure Microsoft SQL Server 数据库。我无法弄清楚为什么它不起作用。当我运行我的 db_connection.php 脚本时,我收到了这个错误:

SQLSTATE[01002] Adaptive Server 连接失败(严重性 9)

当我运行 tsql 命令时,带有我的 azure ms sql 数据库的连接详细信息,连接似乎有效(我读到“1>”表示连接有效):

locale is "C"
locale charset is "ANSI_X3.4-1968"
using default charset "UTF-8"
Default database being set to iBalekaDB
1>

在我的 freetds.conf 文件中,我设置了以下配置:

# server specific section
[global]
        # TDS protocol version
        tds version = 8.0
        text size = 20971520
        client charset = UTF-8

        dump file = /tmp/freetds.log
        debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10


[iBalekaServer]
        host = xxxxxxxx.xxxxxxx.windows.net
        port = 1433
        tds version = 8.0
        client charset = UTF-8

我的 db_connection.php 文件如下所示:

try {

    $dataSource = "dblib:host=iBalekaServer;dbname=iBalekaDB;";
    $username = "xxxxxxxxxxxx";
    $password = "xxxxxxxxxxxx";

    $connectionObject = new PDO($dataSource, $username, $password);
    $connectionObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    if ($connectionObject) {
        echo "<h2>Connection Successful</h2>";
    } else {
        echo "Connection Error";
    }
} catch (PDOException $e) {
    echo $e->getMessage();
}

我在 VPS 上运行 tsql -C 得到了这个:

Compile-time settings (established with the "configure" script)
                            Version: freetds v0.91
             freetds.conf directory: /etc/freetds
     MS db-lib source compatibility: no
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 4.2
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes

我检查了是否安装了 pdo_dblib,当我在我的 Linux VPS 服务器上运行 phpinfo() 时它就存在了。

这可能是什么问题?

编辑:使用 mssql_connect 有效。我真的很想用 PDO

【问题讨论】:

    标签: php sql-server azure


    【解决方案1】:

    在我的测试中,我将$username 更改为UID 的格式(例如&lt;username&gt;@&lt;db_server_name&gt;),它解决了您的SQLSTATE[01002] Adaptive Server connection failed (severity 9) 问题。

    顺便说一句,您可以从 Azure 门户的连接字符串中获取 UID

    另外,如果遇到General SQL Server error: Check messages from the SQL Server (severity 16)的问题,可以参考PDO DBLib not working的回答。

    如有任何更新,请随时告诉我。

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2017-02-15
      • 2014-09-13
      • 2013-12-10
      • 2019-11-20
      • 2015-10-27
      • 1970-01-01
      • 2019-08-19
      • 2022-12-24
      相关资源
      最近更新 更多