【问题标题】:PHP SQL Server 2008 Error Locating Server/Instance Specified [xFFFFFFFF]PHP SQL Server 2008 错误定位服务器/实例指定 [xFFFFFFFF]
【发布时间】:2014-06-12 09:00:30
【问题描述】:

我在将 Windows Apache 连接到 SQL Server Express 2008 时遇到问题

PHP 版本 5.2.9

Apache 版本 Apache/2.2.11 (Win32)

<?php
$serverName = "serverName\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

我尝试使用 mssql 和 sqlsrv 驱动程序,但我无法连接到数据库。这些驱动程序已正确启用。

我可以连接 sqlcmd 应用程序并成功执行查询:

sqlcmd -S serverName\SQLEXPRESS-U userName-P password

当我尝试连接 mssql 驱动程序时:

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: serverName\SQLEXPRESS in C:\xampp\htdocs\ci\demo.php on line 12
Couldn’t connect to SQL Server on $myServer

When i try to connect with sqlsrv driver:

Connection could not be established.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. [message] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [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. [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. ) )

【问题讨论】:

    标签: php sql-server apache sql-server-2008


    【解决方案1】:

    我有同样的问题,我使用了这个代码并且它连接了。数据库服务器是我的案例 10.105.88.99 在另一个机器上

     //i use sql server 2012
    
     $serverName = '10.105.88.99';//only the server name
     $connectionInfo = array( "Database"=>"mydbName", "UID"=>"myUserId", "PWD"=>"myPass");
     $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
     if( $conn ) {
       echo "Connection established.<br />";
     }else{
       echo "Connection could not be established.<br />";
       die( print_r( sqlsrv_errors(), true));
     }
    

    【讨论】:

      【解决方案2】:

      配置 MSSQL Express 2014 连接 remoto PC 或 PHP 等。

      轻松观看视频教程: https://www.youtube.com/watch?v=5UkHYNwUtCo

      【讨论】:

        猜你喜欢
        • 2015-06-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-31
        • 1970-01-01
        • 2016-02-26
        相关资源
        最近更新 更多