Where is the LocalDB database stored?

I wanted to test multiple approaches in building an app (DB first, Model first, code first). After using T4Scaffolding and having lots of issues to DB post modifications, I though EF was not enough flexible. Now I have found a very weird thing. I left a single 'DefaultConnection' specified in Web.Config and is pointing to the single .mdf file in App_Data folder of the solution. Using a Code-First approach, I've created my entities (classes), then scaffolded repositories, context, everything seems to work almost fine, except I get even data which was stored before I 'deleted' and updated the DB. But, after checking in VS Server Explorer, the database only contains Tables used for Identity (Users, Roles), and this shows me that the actual database is somewhere else. I suspect it is located at 'C:\Users{MyUser}\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances'. But I cannot open .mdf files from there to check, since they are already in use. I am stuck. Where is my data???

Forgot to mention that I have two contexts in my application, therefore I receive a warning in PM Console: "More than one context type was found in the assembly ...".

Howerver, the first is 'ApplicationDbContext' and it only refers to Identity DB:

public class ApplicationUser : IdentityUser
{
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

and the second context is bound to that single DB Connection from Web.Config, and it has the business logic entities

Answers


It is little weird. Connection strings are picked from Web.Config and it must be there. Please recheck. Also by default EF creates a database in the App_Data folder. So you can search that folder. Also In case if you find it uncomfortable working with multiple contexts, you can simply copy all the DbSets into ApplicationDbContext, and it should work fine.

Edit: You can specify the same CS for your other context like:

namespace MvcProject 
{     
    public class NorthwindDb : DbContext     
    {         
        public NorthwindDb() : 
            base("DefaultConnection") {}
    }
}  

Here while calling the constructor of base class, we can pass name of the connection string. By default Identity uses DefaultConnection and we can set this to our context.


Need Your Help

Is it possible to get the value for a key in a Hashtable without iteration?

.net hashtable key iteration

Using .NET 3.5, is there a way to retrieve a value from Hashtable corresponding to the key without iteration?

jquery effect .shake() firing strangely in different browsers

jquery jquery-animate

My .shake() effect is giving me the business across multiple browsers. For instance, in Chrome, if I hover quickly, I get a queue buildup problem. If I try implementing .stop() before my shake ef...