0

I am at a loss as to how to fix this issue.

When running my MVC application and trying to access the user database I get the dreaded SQL Network Interfaces, error: 50.

I can see all the data in the Server Explorer in VS, but I can never get the application to see it.

I have spent sometime reading this;

SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance 9

I have renamed and created new databases. I have added/changed the entry in the applicationHost.config file. I have changed the connection string every which way from Sunday. I just cant figure it out. Here is my connection string in the Webconfig file.

 <add name="UserConnection" connectionString="Data Source=(LocalDB)\V11.0;AttachDbFilename=|DataDirectory|\ShopUsers.mdf;Initial Catalog=ShopUsers;Integrated Security=True" providerName="System.Data.SqlClient" />

I even downloaded and ran the ContosoUniversity sample code to see if it works, and it does. Here is that connection string, (that works fine)

<add name="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

It seems there is something amiss between IIS and the db Server.

Any new ideas would be greatly appreciated.

Oh ya, I did have this working just fine on my old PC.

Clint Clark
  • 173
  • 3
  • 14

1 Answers1

0

Seems like you have the database file created already (I suspect you do because of the following segment: AttachDbFilename=|DataDirectory|\ShopUsers.mdf;). If so, then ensure you have it in the same folder beneath your project as the original one on your old PC, usually the |DataDirectory| stands for App_Data (look the answer to this question).

If, you need a brand new database however, you should have tried the following connection string:

<add name="UserConnection" connectionString="Data Source=(localdb)\v11.0\ShopUsers;Initial Catalog=ShopUsers;Integrated Security=True" providerName="System.Data.SqlClient" />

This will create the database for you.

Alexander Christov
  • 9,625
  • 7
  • 43
  • 58
  • I might just have to try and start with a new database and re-populate it. – Clint Clark Aug 22 '17 at 14:43
  • Depends on how much data you have in the .mdf. Have you checked if the file is in App_Data (|DataDirectory|) folder of your project? – Alexander Christov Aug 22 '17 at 14:48
  • Yes file is there. I can see the data in Server Explorer in VS. There isn't a lot of data so I am going to try and start with an empty db. – Clint Clark Aug 22 '17 at 19:57
  • Your decision, as I said, Then mark what I posted as an answer, please. – Alexander Christov Aug 23 '17 at 02:43
  • That doesn't work either. I don't know what I am missing. Probably something stupid simple. Why can I access all the data in Server Explorer, but when I run the site, it can't? – Clint Clark Aug 23 '17 at 20:33
  • Have you checked very carefully the connection string? Spot where it is used. Look for something hard-coded. Trace carefully all the path from creating the DbContext (you use EF, right?) to accessing any of the DbSets. Remove the connection string from where it is defined. Observe app's behaviour - are there any changes? – Alexander Christov Aug 24 '17 at 06:32