我是SQL Server的新手,我正在尝试为一些学校项目学习MVC。 我有一个程序,在Entity框架中使用Code-first方法创建一个DB。 但是当我试图在我的SQL Server Management Studio中找到它时,我没有找到它。 所以我检查了Visual Studio 2013“SQL Server对象资源管理器”,发现我有2个SQL Server实例。 由于我只写一个SQL Server实例,所以我决定删除顶部的那个。 但是一旦我重新启动程序,它就会再次出现。 我怎么才能有1个实例写入? 我写的DB是底部的“TestDB”。
编辑按请求添加数据库上下文
I'm new to SQL Server and I'm trying to learn MVC for some school projects. I have a program that creates a DB with Code-first approach in Entity framework. But when I tried to find it in my SQL Server Management Studio I didn't find it. So I checked in Visual Studio 2013 "SQL Server Object Explorer" and find that I have 2 SQL Server instances. Since I'm only writing to one SQL Server instance I decided to delete the one at the top. But as soon as I restart my program it's there again. How can I only have 1 instance to write to ? The DB I'm writing to is the one at the bottom "TestDB".
Edit Adding DB Context by request
最满意答案
在您的代码中,当前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 。
In Your code currently EF not use at all ConnectionString you expecting.
This is how this should look like:
<connectionStrings> <add name="UserContext" connectionString="Server=.\SQLEXPRESS; User Id=Seeya; Password=;Initial Catalog=CodeFirstTest; Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>and now Your Context:
public class UserContext : DbContext { public UserContext() :base("UserContext") { } //REST OF YOUR CODE }The other instance is because EF craeted SQLCompact, when nothing was given as parameter to base method of Context.
更多推荐
Server,SQL,DB,I'm,电脑培训,计算机培训,IT培训"/> <meta name="descri
发布评论