从PHP到MS SQL的零星连接错误


Sporadic connect errors from PHP to MS SQL

我正在一个用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 。有人经历过这种(不良)做法可能是导致上述错误的原因吗?

如果不是这样,还有其他建议吗?这个问题的原因是什么?

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