2014-06-12 59 views
1

我有我的Windows下的Apache連接到SQL Server Express 2008的PHP SQL Server 2008中錯誤定位服務器/實例指定[xFFFFFFFF的]

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驅動程序,但我無法連接到數據庫。這些驅動程序已正確啓用。 mssql configuration sqlsrv configuration

我可以用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.)) 

回答

4

我有我用這個同樣的問題代碼和它連接。數據庫服務器爲我的情況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)); 
} 
相關問題