I have two DbContext
in my Project : ApplicationDbContext
for ApplicationUser
model (inherited from ASP.NET Identity IdentityUser
class) and EFDbContext
for all other models.
They use one database.
I created two database initializers for each of context:
public class ApplicationDbInitializer :
DropCreateDatabaseIfModelChanges<ApplicationDbContext>
{
protected override void Seed(ApplicationDbContext context)
{
// add Admin role and user
... code here
//
base.Seed(context);
}
}
And
public class EFDbInitializer : DropCreateDatabaseAlways<EFDbContext>
{
protected override void Seed(EFDbContext context)
{
}
}
The problem:
I get such error in App
An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Cannot drop database "DatabaseName" because it is currently in use.
I think it tries re-create database using one context initializer but database is in using by another context.
How to deal with such error?