9

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" />
TheGeneral
  • 79,002
  • 9
  • 103
  • 141
tooold
  • 91
  • 1
  • 1
  • 3
  • Have you looked at your webconfig file to verify that the connection string correct? – Chris Dec 25 '14 at 00:25
  • Here is the connection string. – tooold Dec 25 '14 at 00:33
  • I also tried to use "Data Source = ABC; ...." it doesn't work either. – tooold Dec 25 '14 at 00:37
  • Look at this: http://stackoverflow.com/questions/10540438/what-is-the-connection-string-for-localdb-for-version-11 maybe help. – QMaster Dec 25 '14 at 00:42
  • If you answer a question in the comments with code, please place edit your question and update it so other do not have to read through all the comments to understand your question. – Erik Philips Dec 25 '14 at 00:54
  • Look at AttachDBFilename=|DataDirectory|\aspnet-eManager.Web-2014122322341‌​8.mdf in your connection string. Your application is trying to connect to a SQL database file at that location. Do you actually have this mdf file at that location? – failedprogramming Dec 25 '14 at 01:06
  • @failedprogramming, no, there is no such a file. I thought this is created by migration automatically, am i correct? – tooold Dec 25 '14 at 01:13
  • I can't remember exactly, i think it is created as part of a mvc 4 project template or when you configure Entity Framework. But in either case, there is your problem. – failedprogramming Dec 25 '14 at 01:17
  • What do you mean when you say you created a server name "ABC" on your computer? Did you change your computer name to "ABC" or did you create an SQL instance called "ABC"? If it is the latter, your data source should point to {COMPUTER NAME}\ABC without the braces – failedprogramming Dec 25 '14 at 01:21
  • Check this:http://stackoverflow.com/questions/20217518/sql-server-connection-strings-dot-or-local-or-localdb – ocuenca Dec 25 '14 at 01:49
  • Did you try the last recomendation of @failedprogramming? Also, you can try with Data Source=.\ABC or just Data Source=. – ocuenca Dec 25 '14 at 01:57

3 Answers3

8

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

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
  • Thanks Saruman. There is no database there yet, because I am using EF code first, i think the EF will create the DB for me. When I am using your method 1, after I typed in "(localdb)\v11.0, I did find four database under "select or enter a database name", they are: master, model, msdb, tempdb. if I choose master, the connection string is "Data Source=(localdb)\v11.0;Integrated Security=True". when I use method 2, there is no named pipe shown after step 2. When I use method 3, I got the similar server name as yours, but it still give me similar error message. – tooold Dec 25 '14 at 07:58
  • @tooold yeah i think i lead you down the garden path here – TheGeneral Dec 25 '14 at 08:33
7

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" />

Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
0

To add on to TheGeneral use view - SQL Server Object Viewer and look immediately under the "SQL Server" object. You'll see the name of the connect looking something like "(localDB)\ProjectsV13" Hand enter that into the connection box then you can browse the server for the database you want to use.

Zonus
  • 2,313
  • 2
  • 26
  • 48