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

In my configuration, I have the following:

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 test db, which should fall and recreate every time. Although, when I click "update-database" from the package manager console, even if the database is manually deleted before starting, I get:

It is not possible to delete the 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 is this happening?

+6
source share
1 answer

If you have recently debugged your web application, make sure that IIS Express is not already running and that there are no w3wp.exe processes associated with IIS Express. This process can still be tied to a database connection.

+9
source

Source: https://habr.com/ru/post/950372/


All Articles