Unable to attach file '{0}' as database '{1}'. Code first. Local SQL EXPRESS instance. VS 2010 SP1. Windows XP
I am using Code First approach. I created a local sql express database "Database.mdf" in Visual Studio 2010 SP1 using the MVC 4 pattern. When I try to run my project on my PC, I get the error:
Allow CREATE DATABASE on the database. Unable to connect file "... Database.mdf" as database file "Database".
What I have tried:
-
delete my database using SQL SERVER Object explorer (no results, same error)
-
change connection string (no result, same error)
-
googled on the internet. However, I've seen examples where people are using real SQL servers rather than a local database.
My connection string:
connectionString="Data Source=.\SQLEXPRESS; InitialCatalog=Database; AttachDBFilename=|DataDirectory|\Database.mdf; IntegratedSecurity=true;"
Please note that I am using a local database and not a real SQL SERVER and my Visual Studio is 2010.
I am trying to run this code:
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
How to solve it? Any help would be greatly appreciated!
source to share