Bojje
Bojje

Reputation: 417

Why do I have 2 instances of SQL Server?

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". enter image description here

Edit Adding DB Context by request enter image description here

Upvotes: 0

Views: 172

Answers (1)

madoxdev
madoxdev

Reputation: 3880

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.

Upvotes: 1

Related Questions