Home > Article > Backend Development > 程序写在本机上,数据库在公司里的另外一台电脑上(sqlserver2008),本机上不装任何数据库软件的话,程序能不能连接上数据库
假如我conn.php中输入这样一行代码并运行
存放数据库的电脑ip:192.168.1.221
$conn = sqlsrv_connect("192.168.1.221",array("Database"=>"databasename","UID"=>'sa',"PWD"=>'pass123'))or die(print_r(sqlsrv_errors()));
然后在地址栏输入localhost/cnn.php请问能连接得上吗
报错如下:Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 27 [code] => 27 [2] => [Microsoft][SQL Server Native Client 11.0]Registry information is corrupt or missing. Make sure the provider is installed and registered correctly. [message] => [Microsoft][SQL Server Native Client 11.0]Registry information is corrupt or missing. Make sure the provider is installed and registered correctly. ) [1] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 27 [code] => 27 [2] => [Microsoft][SQL Server Native Client 11.0]Client unable to establish connection [message] => [Microsoft][SQL Server Native Client 11.0]Client unable to establish connection ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 11.0]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][SQL Server Native Client 11.0]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. ) ) 1
SQLSTATE 08001
这是 SQLServer 没有开启远程连接
SQLSTATE 08001
这是 SQLServer 没有开启远程连接
不是!
SQLServer 默认只提供本地服务(所有的数据库都是这样),如果要他提供远程服务,就必须开启远程连接服务