日期:2014-05-18  浏览次数:20747 次

很奇怪的数据库链接问题
1、程序在本机,本机安装的sql 2005,本机程序链接本地2005数据库,没啥问题

2、本机程序链接内网其他IP同样的数据库有问题(此时数据库为:2000),错误信息是:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 

3、本机sql2005数据库的:
  A、SQL Server 2005外围应用配置器 的 服务和连接的外围应用配置器 的 服务 启动了
  B、SQL Server Configuration Manager 的 SQL Server(MSSQLSERVER)启动了
  C、服务和连接的外围应用配置器 的 远程连接 选中的 本地连接和远程连接下的 TCP/IP 和命名管道服务
  D、SQL Server Browser 的服务启动类型为 自动

4、我使用的数据库链接字符串为:
<add name="ConnString" connectionString="persist security info=false;user id=sa;pwd=xxxxxx;Initial Catalog=databaseName;data source=10.0.0.23;" providerName="System.Data.SqlClient"/>
由于数据库名一样,所以在进行本地和远程数据库链接切换时,只是更改了IP地址及相应的User id 和pwd


------解决方案--------------------
我是这样写的
<add name="connectionstring" connectionString="data source='192.168.10.245\SQL2005';initial catalog='databaseName';User Id='sa';Password=''" providerName="System.Data.SqlClient"/>
OR
<add name="connectionstring" connectionString="data source='192.168.10.120';initial catalog='databaseName';User Id='sa';Password=''" providerName="System.Data.SqlClient"/>
------解决方案--------------------
你确认是一个局域网吗,现在还不支持跨局域网的调用数据库