为什么我有2个SQL Server实例?

时间:2016-02-17 09:21:14

标签: c# sql-server model-view-controller

我是SQL Server的新手,我正在尝试为一些学校项目学习MVC。我有一个程序,在Entity框架中使用Code-first方法创建一个DB。但当我试图在我的SQL Server Management Studio中找到它时,我没有找到它。所以我检查了Visual Studio 2013“SQL Server对象资源管理器”,发现我有2个SQL Server实例。由于我只写一个SQL Server实例,所以我决定删除顶部的那个。但是一旦我重新启动程序,它就会再次出现。我怎么才能有1个实例写入?我写的数据库是底部的“TestDB”。 enter image description here

修改 按请求添加DB上下文 enter image description here

1 个答案:

答案 0 :(得分:1)

在您目前的代码EF中,根本不使用您期望的ConnectionString

这应该是这样的:

<connectionStrings> <add name="UserContext" connectionString="Server=.\SQLEXPRESS; User Id=Seeya; Password=;Initial Catalog=CodeFirstTest; Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

现在你的背景:

public class UserContext : DbContext
{
     public UserContext() 
     :base("UserContext")
     {
     }
  //REST OF YOUR CODE
}

另一个例子是因为EF没有作为Context的基本方法的参数给出SQLCompact

相关问题