无法使用PHP sqlsrv_connect连接 - 找不到服务器

I'm using PHP 7.0.15, running IIS locally, and I'm trying to connect to our main SQL Server box. I have successfully loaded the sqlsrv extension, tested with

echo "Did sqlsrv load? " . (extension_loaded('sqlsrv') ? "YES" : "NO");

which returns YES. The SQL instance on the box I'm connecting to is hdnysql1\hdnysql1, verified with select @@serverName. I've checked that I can connect running SQL Server Management Studio using Windows authentication, and I'm trying to use Windows authentication in the code:

$servername = "hdnysql1\hdnysql1";
$connectionInfo = array("Database"=>"MCDB_Test");
$conn = sqlsrv_connect($serverName, $connectionInfo);

This returns a connection failure; sqlsrv_errors returns an array including

Named Pipes Provider: Could not open a connection to SQL Server
Login timeout expired
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.

I followed the instructions here and verified that remote connections are allowed to the server. The TCP port setting in SQL Server Configuration Manager was blank; I set it to 1433 on IP2, restarted services, and things appear to be working; SSRS had to be restarted too but that's working OK. I telnetted to the server on port 1433 to be sure it was open and disabled my firewall, and still no luck -- still getting the same message. Any help would be much appreciated.

php
duai4379
duai4379 命名管道未启用,但我现在启用了它们(并重新启动了服务)并且没有修复它。我尝试了IP地址以及hdnysql1,无论是否使用反斜杠和命名实例。在配置管理器中,它显示IP列表,然后显示IPAll;IP2和IP都显示1433作为端口,所以我认为这意味着服务器正在使用1433.我的DBA告诉我它是一个命名实例;我该怎么做才能确认?谢谢您的帮助!
3 年多之前 回复
donh61500
donh61500 从错误消息中,似乎sqlsrv_connect正在尝试使用命名管道,而不是TCP/IP。您是否验证了SQLServer配置管理器中是否启用了命名管道协议(或检查如何强制sqlsrv_connect不使用命名管道)?您是否尝试使用IP地址而不是hdnysql1作为服务器名称?你说1433-但这通常不是命名实例使用的端口。您确定这是一个命名实例而不是默认实例吗?您确定该服务现在在1433上运行吗?
3 年多之前 回复
doufei2007
doufei2007 是,检查服务器上的服务,并通过刷新指向服务器的SSRS页面进行验证。
3 年多之前 回复
dongzou1964
dongzou1964 sqlserver服务是否正在运行?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问