When I run the application with the following connection string the database file is created successfully.
<add name="ConnString1"
connectionString="Data Source=.\SQLEXPRESS;
Database=Database1;
Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
If I delete the database file and try to run the application again the database file fails to be created and I get the following inner exceptions:
The underlying provider failed on Open.
{"Cannot open database \"Database1\" requested by the login. The login failed.\Database1\nLogin failed for user 'computer\\someuser'."}
If I change Database=Database1 to Database=Database2 in the connection string then the database file is created successfully. The problem repeats itself always.
How can I recreate the database file without having to change the database name?
Check to make sure the directory rights allow you to delete the mdf file and the the login has drop schema/table privileges directory rights are a common issue with mdf files due the high security placed on these files due to their potentially sensitive nature
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