Entity Framework Code First can't find database in server explorer
Asked Answered
N

5

10

So I was following this introduction to the Entity Framework Code First to create a new database ( https://msdn.microsoft.com/en-us/data/jj193542 ) and I followed the example completely. Now I want to add it to my server explorer in Visual Studio 2013.

Tried both LocalDb ((localdb)\v11.0) or SQL Express (.\SQLEXPRESS) but the database doesn't show, I know it's working because I've tested it multiple times now and it keeps appending and fetching data from the database, so where would it be residing?

Besides the default Visual Studio 2013 I have an SQL Server setup. Thanks

config

<configuration> 
  <configSections> 
    <!-- For more information on Entity Framework configuration, visit go.microsoft.com/fwlink/… --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
  </configSections> 
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
  </startup> 
  <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
      <parameters> 
        <parameter value="mssqllocaldb" /> 
      </parameters> 
    </defaultConnectionFactory> 
    <providers> 
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
  </entityFramework> 
</configuration>
Noodle answered 4/6, 2015 at 22:53 Comment(7)
could you paste your connection string?Bourke
@Bourke in the video he didn't edit the app.config or at least not till 3:50. By default it goes to localDB does it not?Noodle
may be you stored in your SQL server. Try connecting Server name with dot symbol . and drop down select database nameBourke
@Bourke Tried it but didn't anythingNoodle
ok. please do this: got to web.config and please paste your connection string, then we find out what it is?Bourke
@Bourke There's no connection string in the app.config (it's console). Should there be any? What I understand from the video is that it generates a database from the context and puts it in localdb or sqlexpressNoodle
Let us continue this discussion in chat.Bourke
B
16

Looking at your config (supplied during chat) I can see that your EF is using localdb and MSSQLLocalDB instance. Try:

(localdb)\MSSQLLocalDB
Bourke answered 5/6, 2015 at 0:0 Comment(0)
G
5

I figured out where my database is by doing the following:

  • put a breakpoint in the first place where I call context or dbcontext or whatever you want to call it
  • when you're on that breakpoint, drill down into Database -> Connection and somewhere in there you'll find your connection string.
Gabriel answered 11/5, 2016 at 17:49 Comment(0)
V
0

Following the Microsoft exemple in VS2015 I had the same problem and the right ServerName was: (localdb)\MSSQLLocalDB and Database was: CodeFirstNewDatabaseSample.Program+BloggingContext enter image description here

Vilipend answered 26/5, 2017 at 11:56 Comment(0)
S
0

In Visual Studio look for the DB in the SQL Server Object Explorer window. If you can't find it there do the following:

  1. Open SQL Server Management Studio.
  2. Find your DB
  3. Right click on the DB and choose Properties
  4. Find out to which server the DB belongs (e.g. your-name\SQLEXPRESS)
  5. Back to Visual Studio: Connect to the server in SQL Server Object Explorer
  6. The database is under Databases.
  7. Choose the database. In the Properties window look at the Data File property. This is where the path to the database file is.
Shellbark answered 18/12, 2017 at 7:43 Comment(0)
C
0

step 01: right what ever database shows under SQL sever tab(in server object explorer) then select disconnect. after that you can re connect it . then you will see your database.

if it is not . go to search next to windows logo(start) search for services . find mssqlserver then check those are started. if it isn't then you can start those. then after that repeat step 01.

Carmella answered 4/4, 2020 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.