1

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.`

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Igorski88
  • 985
  • 1
  • 9
  • 19
  • According to stack trace it looks like either you don't have enough permission or SQL server is not running in your PC. you can explicitly try it by going to ,Services->SQL server-> Right click on START or RESTART. – M_K Dec 21 '17 at 21:58
  • don't use localdb in production. move all your data to SQL server and do it there. Also find out your sql server's connection string in Sql server management studio – Steve Dec 21 '17 at 22:17
  • @steve why is using localdb not suitable for production? If I move all my data to SQL Server How can I work on the project at a location with no internet. I usually work on the project in locations with no connectivity and then once I get to a location with internet I publish the site. This is why localdb was so attractive to me. – Igorski88 Dec 21 '17 at 23:03
  • @Igorski88 just make a copy and update any data you like when the code is production ready. "LocalDB is a lightweight version of the SQL Server Express Database Engine that is targeted for program development" – Steve Dec 22 '17 at 14:33
  • @Steve I was expecting this type of answer but I guess I hope for an easier way. So should I just comment out the connection string to the SQL server and uncomment it every time I want to publish? Vice versa W/localdb connection string. Is there an easy way to copy localdb data into SQL Server? – Igorski88 Dec 23 '17 at 00:25
  • when you publish you can config the web.config to rewrite your sql connection string rule to use a different string. as for copying, depending on what you are copying. You shouldn't mess with production data anyways – Steve Dec 23 '17 at 20:25

1 Answers1

0

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

Igorski88
  • 985
  • 1
  • 9
  • 19