问题
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