简体   繁体   中英

Getting SQL Server error in ASP.net application when using different computer

I have a simple ASP.NET C# application which works fine on the computer it was created. However, whenever this project is compiled and run on any other computer, I get the following error:

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

On the following line:

bool admin = HttpContext.Current.User.IsInRole("Admin");

I could previously run the application on a different computer without error. I have made no changes to any SQL server settings.

In Web.config file:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-INT422Project-20140320070224.mdf;Initial Catalog=aspnet-INT422Project-20140320070224;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="DataContext" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=Lab5;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|INT422Project.mdf" />
</connectionStrings>

Your better change your connection String value to use a real sql server database.

SQL Server Express or LocalDB is not used for production web applications because it is not designed to work with IIS.

Please check the following:

  1. Make sure the sql server service is up and running.
  2. Make sure the TCP/IP ports are enabled.

If both are fine, I would suggest you to read the servername and database name from the app.config/ web.config which makes life easier.

Dude, Check this answer.

https://stackoverflow.com/a/16054490/3081461

you can read more about localdb at microsoft TechNet as well : http://technet.microsoft.com/en-us/library/hh510202.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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