0

I have a solution with an ASP.NET MVC web project and an Infrastructure (DAL) project. I have the following connection string in both config files:

<connectionStrings>
    <add name="MyContext" 
         connectionString="Data Source=localhost;Initial Catalog=MyDB;User Id=dbuser; Password=WS7jHVNKTT20J7HxsG9odv1Uqf5CUu; Multipleactiveresultsets=True;Application Name=EntityFramework;"
         providerName="System.Data.SqlClient" />
</connectionStrings>

I set up the user in SQL Server 2014 Management Studio with the right privileges. I installed Entity Framework and enabled migrations for the infrastructure project and created the database to begin with, but have since messed it up.

I changed the model too much, and my migrations eventually failed. So when all else failed I completely removed the migrations folder and deleted the database from the management studio (mind you there were no data yet). I did this hoping I could just retrace my steps, and I have up until the database-update command. I now get this error constantly:

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)

I tried all of the solutions to this question, but they did not make sense to me as it was all still on localhost (see connection string).

I am at my wits end, can someone please enlighten me to my mistakes?

Community
  • 1
  • 1
Kasper
  • 290
  • 1
  • 2
  • 11
  • Use this query string : ` ` – Saurabh Srivastava Feb 21 '17 at 17:18
  • Same thing I'm afraid. – Kasper Feb 21 '17 at 17:33
  • NO just use `.` instead of localhost in your `Data Source` – Saurabh Srivastava Feb 21 '17 at 17:33
  • Sorry, I meant I get the same error. – Kasper Feb 21 '17 at 17:34
  • Go through Control-Panel/Admin/ODBC and add a (temporary) DSN, and use the credentials you have in your connection string above. If you cannot connect through DSN, then the issue is not EntityFramework related. Aka, this little temp-task will help you distinquish between a generic connection error vs something specific to EF. – granadaCoder Feb 21 '17 at 18:24
  • Okay.. What data source should I choose? ODBC Driver 11 or 13 or SQL Server or SQL Server Native Client 11? – Kasper Feb 21 '17 at 18:35
  • @granadaCoder: So I tried what you said, and it connected without any problems, meaning Entity Framework is messed up somehow. I then tried the top suggestion from [this](http://stackoverflow.com/questions/32195745/update-the-database-from-package-manager-console-in-code-first-environment) issue, and that worked fine. So I guess Entity Framework can't access my connection string properly? – Kasper Feb 22 '17 at 07:05

1 Answers1

1

This turned out to be a silly mistake on my part. I initially configured my context to use this connection string

base("name=MyContext")

I found out that this can sometimes give problems in Entity Framework 6 so I just removed the name= part, except I accidentally added a space so it became

base(" MyContext")

Rookie mistake, I know, but at least it won't happen again.

Kasper
  • 290
  • 1
  • 2
  • 11