Cannot drop database because it is currently in use - EF code-first

connection-string ef-code-first entity-framework

Question

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?

1
6
7/26/2013 4:05:17 PM

Accepted Answer

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.

9
7/26/2013 4:20:44 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow