0
votes

I have a new windows 2019 server running IIS with PHP 7.4.x and is working properly and the sql server and odbc drivers were installed.

Now when I try to connect to a remote mssql instance , I get the following error.

$serverName = "//servername\dbinstance";
$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 installed SSMS on the php server and I can connect to the remote database server without any problems!

What did I do wrong with php?

In linux, it may fail because of SELinux turned on but this is Windows 2019 LOL

thoughts?

thanks

1
Can you post the actual error message? - Chris Haas
Can you see the connection attempt in the SAL Server logs? If so, what is the connecy error logged there as well? If not, then the connection details aren't reaching it and therefore are likely wrong. - Larnu
I'm not that familiar with SQL server. Is your database instance literally called dbinstance or something else that starts with n, r, t or some other character that is transformed into something else when combined with a single backslash? Can you connect if you escape the backslash ("//servername\\dbinstance")? - rickdenhaan
Could not connect. Array ([0] => Array([0] => 08001[SQLSTATE] => 08001[1] => 161[code] => 161[2] => [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [161].[message] => [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [161].)[1] => Array([0] => HYT00[SQLSTATE] => HYT00[1] => 0[code] => 0[2] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired[message] => [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired)[2] =>... - Lawrence
.r]Login timeout expired)[2] => Array([0] => 08001[SQLSTATE] => 08001[1] => 161[code] => 161[2] => [Microsoft][ODBC Driver 17 for SQL Server]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][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. - Lawrence

1 Answers

0
votes

I figured it out... weird,,, you don't need the instance name and just use the server name