问题
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
ordbcontext
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:
- Open SQL Server Management Studio.
- Find your DB
- Right click on the DB and choose Properties
- Find out to which server the DB belongs (e.g. your-name\SQLEXPRESS)
- Back to Visual Studio: Connect to the server in SQL Server Object Explorer
- The database is under Databases.
- 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