我在web.config中有这样的SQL连接设置:
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=SQLServer;Initial Catalog=DBName;User ID=domain\username;Password=password
providerName="System.Data.SqlClient" />
</connectionStrings>
在我的开发机器上一切正常,但是当我穿上网络服务器时,我一直得到:
Inner Exception Type: System.ComponentModel.Win32Exception
Inner Exception: The network path was not found
Inner Source:
Exception Type: System.Data.SqlClient.SqlException
Exception: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Web服务器到达SQL服务器没有问题,我猜我的连接字符串语法有问题。
有人能发现任何错误吗?
答案 0 :(得分:1)
如果您使用的是SQL Express,请使用
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=Server\SqlExpress;Initial Catalog=DBName;User ID=username;Password=password
providerName="System.Data.SqlClient" />
如果工作正常则更新
答案 1 :(得分:0)
是你的SQL Express版吗?如果是,那么请使用以下连接字符串
DATA SOURCE=ipaddress_of_sql_machine\sqlexpress;UID=sa;PWD=;DATABASE=databasename
如果您没有sql express,请转到以下连接字符串
DATA SOURCE=ipaddress_of_sql_machine;UID=sa;PWD=;DATABASE=databasename
希望有所帮助
答案 2 :(得分:0)
检查您的计算机和服务器是否位于不同的域中。这可能会有所帮助:
http://www.codeproject.com/Questions/335874/A-network-related-or-instance-specific-error-occur