问题描述
这是一个常见主题,在此之前已经被问了好几次了。我已经经历了其中一些,但无法使其正常工作。
我正在尝试使用以下代码从MSsql Server
连接一个PHP
数据库。
$serverName = "cl-t139-086cn\\MSsqlSERVER"; //serverName\instanceName
$connectionInfo = array( "Database"=>"AutoTrader","UID"=>"user_id","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));
}
我尝试了以下两种变体,但没有任何作用
$serverName = (local)\MSsqlSERVER
$serverName = localhost\MSsqlSERVER
实例名称为MSsqlSERVER,我通过运行services.mfc
在Windows服务中签入。
数据库用户名和密码也是正确的,因为在同一服务器上运行但使用.NET构建的另一个运行Web.config文件中使用了相同的凭据。
扩展名sqlsrv
已安装并启用,可以通过运行phoinfo()
进行检查。
Connection Could not be established. Array ( [0] => Array ( [0] => 08001 [sqlSTATE] => 08001 [1] => 87 [code] => 87 [2] => [Microsoft][ODBC Driver 17 for sql Server]sql Server Network Interfaces: Connection string is not valid [87]. [message] => [Microsoft][ODBC Driver 17 for sql Server]sql Server Network Interfaces: Connection string is not valid [87]. ) [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] => Array ( [0] => 08001 [sqlSTATE] => 08001 [1] => 87 [code] => 87 [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. 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. ) )
环境:
我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)