active92 active92 - 1 month ago 13
SQL Question

Unable to find database in SQL Server Management Studio

I'm currently following Entity Framework Tutorial. The code manage to run successfully. I am also able to retrieve the data.

However, I could not find my database in

SQL Server Management Studio
.

This is my connection string

<connectionStrings>
<add name="MyContextDB" connectionString="data source=.\SQLEXPRESS;Initial Catalog=EFMyContextDB;integrated security=True;user instance=True;multipleactiveresultsets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>


This is my DbContext

public class MyContext : DbContext
{
public MyContext() : base("name = MyContextDB") { }
public virtual DbSet<Course> Courses { get; set; }
public virtual DbSet<Enrollment> Enrollments { get; set; }
public virtual DbSet<Student> Students { get; set; }
}

Answer

If you are using user instance=True; the database will only exist under your currently logged in users context. Im not too sure what impact this has in SSMS but it may be that you need to be logged in as that user to SSMS also

More info here:

https://technet.microsoft.com/en-us/library/ms143684(v=sql.105).aspx