0

我正在开发一个用 PHP 编写的站点(在 Apache 下的 Windows Server 上运行),并使用 MS SQL Server 2005 作为数据库(在另一个 Windows Server 上)。

运行时偶尔会出现此错误sqlsrv_connect

Sql State: 08001
Code:      53
Message:   [Microsoft][SQL Server Native Client 10.0]
           A network-related or instance-specific error has occurred while 
           establishing a connection to SQL Server. Server is not found or not 
           accessible. Check if instance name is correct and if SQL Server is 
           configured to allow remote connections. For more information see SQL 
           Server Books Online.

我已经查看了其他人遇到此错误的许多讨论中的一些,但其中大多数与设置中的基本错误有关,这些错误会导致数据库完全无法访问。(如上所述 - 问题是零星的。)

我已消除的另外两个可能的错误来源是 DNS - 我在连接字符串中使用服务器的 IP 地址,并且服务器没有任何明显的过载。它有大量可用资源,并且活动监视器不会显示任何运行成本过高的查询或长时间运行的后台作业。

这是发生错误的代码:

    $conn = sqlsrv_connect(
        "[snip ip number of server]",
        array(
            'Database' => '[snip database name]',
            'LoginTimeout' => 5,
            'CharacterSet' => 'UTF-8',
            'UID'=>'[snip user name]',
            'PWD'=>'[snip password]'
        )
    );
    $res = array();
    $status = array();
    /* check for connection errors */
    if($debug) {
        if( !$conn ) {
            if( ($errors = sqlsrv_errors() ) != null)
                ...error handling here...

上面的代码不是我写的——我通常对它的编写方式并不满意。

sqlsrv_connect 每次需要向数据库发送查询时,代码都会调用。有没有人经历过这种(不良)做法可能是导致上述错误的原因?

如果不是这种情况,是否还有其他建议。这个问题的原因是什么?

4

1 回答 1

0

重新启动我们的 SQL Server 后,该错误停止出现。我将此标记为过于本地化。

于 2013-08-27T08:20:54.547 回答