简体   繁体   English

ASP.net未连接到SQL

[英]ASP.net not connecting to SQL

I have a SQL connection setup like this in web.config: 我在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>

On my dev machine all works fine, but when putting on web server I keep getting: 在我的开发机上,一切正常,但是在安装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)

The web server has no problem reaching the SQL server, I am guessing there is something wrong with my connection string syntax. Web服务器到达SQL Server没问题,我猜我的连接字符串语法有问题。

Can anyone spot anything wrong? 谁能发现任何错误?

if you are using the SQL Express then use like 如果您使用的是SQL Express,则使用like

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

update if it working fine 更新是否正常

Is it your SQL Express edition ? 是您的SQL Express版本吗? if yes then go with following connection string 如果是,则使用以下连接字符串

DATA SOURCE=ipaddress_of_sql_machine\sqlexpress;UID=sa;PWD=;DATABASE=databasename

if you don't have sql express then go for following connection string 如果您没有sql express,请输入以下连接字符串

DATA SOURCE=ipaddress_of_sql_machine;UID=sa;PWD=;DATABASE=databasename

hope it helps 希望能帮助到你

Check if your machine and server are in different domain. 检查您的机器和服务器是否在不同的域中。 This may help : 这可能会有所帮助:

http://www.codeproject.com/Questions/335874/A-network-related-or-instance-specific-error-occur 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