Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Connection to localDb

I am trying to follow the pluralsight course ASP.NET MVC 4 Fundamentals. But can't have my database connected.

Here is the error I got:

An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.

I have visual studio 2013 professional and SQL server 2012 installed on my machine. When I installed my SQL server, I created a server name "ABC" on my computer.

I have also installed sql localdb 11.0 separately, but it seems VS can't find the localDb connection. When I check Server Explorer -> add Connection, under server name list, only "ABC" is shown up.

Here is the connection string.

I also tried to use "Data Source = ABC; ...." it doesn't work either.

Update

Here is my connection string

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-eManager.Web-20141223223418;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-eManager.Web-2014122322341‌​8.mdf" providerName="System.Data.SqlClient" />
like image 960
tooold Avatar asked Dec 25 '14 00:12

tooold


2 Answers

You could try this

  1. In server explorer, right click, Choose Add Connection
  2. enter (localdb)\v11.0 in as the server name
  3. Choose your database and press connect
  4. Right click properties on your new connection
  5. Use that connection in string in your default connection

I.e.

<add name="DefaultConnection" connectionString="<Paste-connection-string-here>" providerName="System.Data.SqlClient" />

If that doesn't work, lets try starting it from the command line

  1. Open command prompt
  2. Run SqlLocalDB.exe start v11.0

Follow original steps , use the named pipe as your server name


If that doesn't work, lets try and connect via named pipes

  1. Open command prompt
  2. Run SqlLocalDB.exe info v11.0
  3. Copy the Instance pipe name that starts with np:...

Follow original steps , use the named pipe as your server name

e.g

enter image description here

like image 130
TheGeneral Avatar answered Oct 16 '22 10:10

TheGeneral


Run this command to make sure what is the version of your LocalDB sqllocaldb info sqllocaldb info command result

So in my case the version is MSSQLLocalDB then the connection string will look like this

<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=IdentityManagerDB;Integrated Security=True" providerName="System.Data.SqlClient" />

like image 30
Wahid Bitar Avatar answered Oct 16 '22 10:10

Wahid Bitar