i'm trying following in ef codefirst seed method:
protected override void seed(testdbcontext context) { sqlconnection.clearallpools(); context.database.delete(); context.database.createifnotexists(); if (!webmatrix.webdata.websecurity.initialized) { websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "userid", "username", autocreatetables: true); } }
this fails error 'cannot delete because database in use'. seems happen after run api project, initializes own connection membership tables:
private class simplemembershipinitializer { public simplemembershipinitializer() { database.setinitializer<userscontext>(null); try { using (var context = new userscontext()) { if (!context.database.exists()) { // create simplemembership database without entity framework migration schema ((iobjectcontextadapter)context).objectcontext.createdatabase(); } } if (!webmatrix.webdata.websecurity.initialized) { websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "userid", "username", autocreatetables: true); } } catch (exception ex) { throw new invalidoperationexception("the asp.net simple membership database not initialized. more information, please see http://go.microsoft.com/fwlink/?linkid=256588", ex); } } }
any idea how can working code (i'm trying testing automated)?
on server explorer, right click data connection db , choose close connection.
Comments
Post a Comment