假如我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 没有开启远程连接


就是说连接远程(192.168.1.221)的数据库是通过我这边的服务器上的数据库连接上的,如果我的服务器上没有安装sqlserver就不能连接到远程的数据库对吗

不是!
SQLServer 默认只提供本地服务(所有的数据库都是这样),如果要他提供远程服务,就必须开启远程连接服务

09-18 11:06