PHP Sqlsrv connection not working when specify port, instance

半城伤御伤魂 提交于 2021-01-29 13:56:49

问题


PHP version:7.4, SQL Server version:2019,

I was going to try to specify port in connection but it didn't work.

<?php

$serverName = "MYPCNAME, 1433";
$connectionInfo = array( "Database"=>"MyDB", "UID"=>"sa", "PWD"=>'MyPassword');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
     echo "Connection established.";

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

?>

Above showed below message.

 [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: An existing connection was forcibly closed by the remote hos

When I removed port like this $serverName = "MYPCNAME" , it worked well.

I changed port to 1434, and tested again (Of course I restarted SQL Server, firewall set).

$serverName = "MYPCNAME, 1434"

This gave me same error but $serverName = "MYPCNAME" This worked well.

I tried to specify instance name too, but there was same issue.

I installed php_sqlsrv, php_pdo_sqlsrv well and in phpinfo(), they are displayed as installed successfully.

Is there anything what I missed?

Can anyone help me?

来源:https://stackoverflow.com/questions/62134472/php-sqlsrv-connection-not-working-when-specify-port-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!