欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

程序写在本机上,数据库在公司里的另外一台电脑上(sqlserver2008),本机上不装任何数据库软件的话,程序能不能连接上数据库

程序员文章站 2022-06-05 08:28:57
...
假如我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 默认只提供本地服务(所有的数据库都是这样),如果要他提供远程服务,就必须开启远程连接服务