In my configuration I have this:
public sealed class Configuration : DbMigrationsConfiguration<App.Repository.NogginatorDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(AppDbContext context)
{
SqlConnection.ClearAllPools();
//context.Database.CreateIfNotExists();
System.Data.Entity.Database.SetInitializer(new DropCreateDatabaseAlways<AppDbContext>());
if (!WebMatrix.WebData.WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("TestConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
}
}
}
This is used for a test db that should drop and recreate every time. Though when I hit "update-database" from the package manager console, even if the database is deleted manually prior to running, I get:
Cannot drop database "Nogginator.Test" because it is currently in use.
My connection string:
<add name="TestConnection"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\;Initial Catalog=App.Test;Trusted_Connection=True;MultipleActiveResultSets=True;" />
Why would this be happening?
If you were recently debugging your web application, ensure that the IIS Express isn't still running and that there are no w3wp.exe processes associated with IIS Express. This process may still be holding on to a database connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With