50l3r 50l3r - 26 days ago 8
Apache Configuration Question

PHP SQL Server 2008 Error Locating Server/Instance Specified [xFFFFFFFF]

I have a problem connecting my Windows Apache to a SQL Server Express 2008

PHP Version 5.2.9

Apache Version 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));
}
?>


I try with mssql and sqlsrv drivers but i cant connect to database. These drivers are correctly enabled.
mssql configuration
sqlsrv configuration

I can connect with sqlcmd application and execute queries succesfully:

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


When i try to connect with mssql driver:

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. ) )

Answer

i had the same problem i used this code and it connected.the database server was for my case 10.105.88.99 on anther machine

 //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));
 }