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

时间:2016-03-14 08:22:33

标签: c# sql-server asp.net-mvc entity-framework

我在做微软的MVC入门教程:

Getting Started with Entity Framework 6 Code First using MVC 5.

这包括创建代码优先数据库。

一切正常,但我无法找到我的数据库。

这是我的ConnectionString

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

如果我调试索引方法,则连接如下:

Data Source=.\SQLEXPRESS; Integrated Security=True

但我的SQLEXPRESS实例中没有数据库,我已经使用SQL Server Management Studio进行了检查。

如果我在文件系统中搜索*.mdf,我也无法找到任何内容。

我的项目中的

App_Data是空的......

但是所有CRUD操作都运行良好,必须有一些东西。

我能看到该表的唯一方法是通过Visual Studio Server Explorer连接到.\SQLEXPRESS。但这个位置在哪里?如果我通过SQL Server Management Studio连接到.\SQLEXPRESS,为什么我看不到该表?

有什么想法吗?

1 个答案:

答案 0 :(得分:12)

您没有在连接字符串中指定Initial Catalog,因此您可能正在使用Master数据库。

您需要像这样指定Initial catalog

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