简体   繁体   English

无法找到我的EF代码第一个数据库

[英]Cant find my EF code first database

I am doing Microsoft's MVC getting started tutorial: 我正在做Microsoft的MVC入门教程:

Getting Started with Entity Framework 6 Code First using MVC 5. 实体框架6入门代码首先使用MVC 5。

This includes the creation of a code first database. 这包括创建代码优先数据库。

It all works fine, but I am not able to find my database. 一切正常,但我无法找到我的数据库。

This is my ConnectionString : 这是我的ConnectionString

<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True" providerName="System.Data.SqlClient"/>

If I debug my index Method the connection is as follow: 如果我调试我的索引方法连接如下:

Data Source=.\SQLEXPRESS; Integrated Security=True

But there is no Database in my SQLEXPRESS Instance, I have checked it with SQL Server Management Studio. 但是我的SQLEXPRESS实例中没有数据库,我已经使用SQL Server Management Studio进行了检查。

I also cant find anything if I search my filesystem for *.mdf . 如果我在文件系统中搜索*.mdf我也找不到任何东西。

App_Data in my Project is Empty... 我项目中的App_Data为空...

But all CRUD operations are working fine, there has to be something. 但是所有的CRUD操作都运行良好,必须有一些东西。

The only way I can see that table is to connect to .\\SQLEXPRESS via the Visual Studio Server Explorer. 我能看到该表的唯一方法是通过Visual Studio Server Explorer连接到.\\SQLEXPRESS But where is this physically located? 但这个位置在哪里? Why cant I see the table if I connect to .\\SQLEXPRESS via SQL Server Management Studio? 如果我通过SQL Server Management Studio连接到.\\SQLEXPRESS ,为什么我看不到该表?

Any idea? 任何想法?

You didn't specify the Initial Catalog in your connection string so probably you are using the Master database. 您没有在连接字符串中指定Initial Catalog ,因此您可能正在使用Master数据库。

You need to specify the Initial catalog like this: 您需要像这样指定Initial catalog

<add name="MovieDBContext" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=yourDBName;Integrated Security=True" 
     providerName="System.Data.SqlClient"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM