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

◇◆丶佛笑我妖孽 提交于 2020-01-24 03:26:08

问题


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>

回答1:


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

(localdb)\MSSQLLocalDB



回答2:


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.



回答3:


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




回答4:


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.


来源:https://stackoverflow.com/questions/30655565/entity-framework-code-first-cant-find-database-in-server-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!