So I successfully got my solution to create and initialize the Identity database. The problem now is, as I am working on it I keep getting this error
Cannot create file 'C:\Webs\SomeScheduler\SomeScheduler\App_Data\SomeSchedulerUsers.mdf'
because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
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 create file
'C:\Webs\SomeScheduler\SomeScheduler\App_Data\SomeSchedulerUsers.mdf'
because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
I know that it already exists, that is what I want. How do I stop it from trying to re-create it every time I try to run my code as I develop this site?
As always, any and all help is greatly appreciated.
Add the following line to your context constructor
Database.SetInitializer<YourContextClass>(null);
This should be enough.
But if you want to create the database only if it doesn't exists and correctly configure migrations, take a look at this question How to avoid recreate an existing database using automatic Code First Migration
You might be able to get away with adding this
<contexts>
<context type="Blogging.BlogContext, MyAssembly" disableDatabaseInitialization="true" />
</contexts>
to your Web.config. Of course changing Blogging.BlogContext, MyAssembly
to more accurately reflect your model.
Source
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