繁体   English   中英

ASP.net未连接到SQL

[英]ASP.net not connecting to SQL

我在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>

在我的开发机上,一切正常,但是在安装Web服务器时,我不断得到:

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 Server没问题,我猜我的连接字符串语法有问题。

谁能发现任何错误?

如果您使用的是SQL Express,则使用like

<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=Server\SqlExpress;Initial Catalog=DBName;User ID=username;Password=password
  providerName="System.Data.SqlClient" />

更新是否正常

是您的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

希望能帮助到你

检查您的机器和服务器是否在不同的域中。 这可能会有所帮助:

http://www.codeproject.com/Questions/335874/A-network-related-or-instance-specific-error-occur

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM