为什么我有2个SQL Server实例?(Why do I have 2 instances of SQL Server?)

编程入门 行业动态 更新时间:2024-10-27 03:26:44
为什么我有2个SQL Server实例?(Why do I have 2 instances of SQL Server?)

我是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

本文发布于:2023-04-29 07:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335982.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我有   实例   Server   SQL   instances

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!