I'm using Brock Allen's awesome MembershipReboot library to provide identity services in my .NET application. Per Getting Started with MembershipReboot, MembershipReboot uses Entity Framework (EF) for it's data access.
The sample apps contain a SQL Server database MembershipReboot.mdf. From this database I exported the schema and data and imported it into my application's database (MyTestApp.mdf - see below).
You can see where MembershipReboot.mdf comes from as the samples that accompany MembershipReboot define the following connection string::
<add name="MembershipReboot" connectionString="Data Source=(LocalDb)\bla;Initial Catalog=MembershipReboot;Integrated Security=True" providerName="System.Data.SqlClient"/>
I set the following connection string for my app's database:
<add name="DefaultConnectionString" connectionString="Server=(LocalDb)\bla;AttachDbFilename=|DataDirectory|\MyTestApp.mdf;Initial Catalog=MyTestApp;Integrated Security=True" providerName="System.Data.SqlClient" />
Until recently, all was well. Then, upon one launch of my application I started receiving - intermittently - the following error upon first database access:
Cannot attach the file 'C:\Users\mkrieger\Google Drive\Projects\MyTestApp\MyTestApp\App_Data\MembershipReboot.mdf' as database 'MembershipReboot'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot attach the file 'C:\Users\mkrieger\Google Drive\Projects\MyTestApp\MyTestApp\App_Data\MembershipReboot.mdf' as database 'MembershipReboot'.
I did a full text search of my application's directory followed by a Strings search of the executables and all binary files for "MembershipReboot.mdf" but came up empty.
What am I missing?
Brock Allen has seen this problem before (the problem has nothing whatsoever to do with MembershipReboot or any particular library).
Yes, I’ve seen this error before. It’s when you delete the sql express files (mdf, etc) but don’t delete the DB from the DB server – in other words, you need to delete the database from within Sql Server Mgmt Studio or from the Sql Server explorer in Visual Studio.
This did the trick for me.