简体   繁体   中英

Publishing ASP.net website With LocalDB

I'm trying to publish my website on a different computer that is on my home network. I have set up IIS and SQL Server 2016 Express on that computer. Same version on my development laptop. When I run the site I get the below error. I think the problem might be that I'm trying to us LocalDB. I'm often traveling and in areas where I don't have internet connectivity. This is why I thought it would be best to use localDB while developing. Once I get home I then publish to my Server.

Originally the LocalDB was created on my computer in a folder that was far from my project. So what I did was move it to the app_data so that it would be attached when I publish.

What I tried:

  1. Reinstalled Microsoft SQL Server 2016 (made sure LocalDB was installed)
  2. Ensured the database was in fact in App_Data folder on server
  3. Changed connection string to look for database in app_data

Any suggestion would be great.

Connection string:

<connectionStrings 
    <add name="IgorsSellersToolBoxDB" 
         connectionString="metadata=res://*/Models.ModelDB.csdl|res://*/Models.ModelDB.ssdl|res://*/Models.ModelDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source= LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\IgorsSellersToolBoxDB.mdf;integrated security=True;multipleactiveresultsets=True;connect timeout=30;application name=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>

Error:

Server error in '/WebToolbox' Application.

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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. )

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.)

Source error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.`

As Steve mentioned in the comments, I have confirmed that using localDB in production is frowned upon.

Solution: Use a SQL Server on my development machine and a separate one on my production server. All I have to do is have separate connection strings in my Web.Config.

In your web.config, you can expand the file in the solution explorer, and you will see two files:

  • Web.Debug.Config
  • Web.Release.Config

There is a great answer here that explains it very well --> Using different Web.config in development and production environment

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