sql - 从 Code First 创建的数据库显示在服务器资源管理器中,而不是 SQL Server 对象资源管理器中

标签 sql asp.net-mvc entity-framework visual-studio

数据库“EFCheck”(首先由 Entity Framework 代码创建)显示在服务器资源管理器中,而不是 SQL Server 对象资源管理器中,并且我在 SQL Server 中没有看到创建的数据库。谁能告诉我在 SQL Server 中哪里可以看到新数据库?

Server Explorer where I see the new EFCheck db created by EF

SQL Server Object Explorer where I don't see the EFCheck db

Web.Config 中的我的连接字符串

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

DbContext

public class Db : DbContext { 
   public Db() : base("name=Db") { } 
   public virtual DbSet<Blog> Blogs { get; set; } 
   public virtual DbSet<Post> Posts { get; set; } 
} 

最佳答案

您没有在连接字符串中指定初始目录。您必须如下所示设置初始目录

<add name="Db" 
connectionString="Data Source=ABHI\SQLEXPRESS;
Initial Catalog=Your-Db-Name-Should-Be-Set-Here;
Integrated Security=True" providerName="System.Data.SqlClient"/>

关于sql - 从 Code First 创建的数据库显示在服务器资源管理器中,而不是 SQL Server 对象资源管理器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39188329/

相关文章:

c# - Entity Framework 中推荐的身份生成方法是什么?

sql - Oracle OR 条件使查询非常慢

c# - 从 .NET 调用表值 SQL 函数

c# - 我如何在 visual studio 2012 中更正 wpf datagrid 列名称冗余

javascript - TinyMCE Editor 不具备所有功能

c# - asp.net mvc 区域和主站点具有/相同的 Controller 名称

c# - 获取 User.identity 的名字和姓氏

c# - 在 EF 6 中使用 .Contains()

mysql - SQL - 确定是否存在具有特定电子邮件的用户的订单?

c# - 组合表达式(表达式<Func<TIn,TOut>> 与表达式<Func<TOut, bool>>)