Question

In VS 2012 I created a new MVC 4 project starting from the internet application template, then changed its properties to use SQL Server Express instead of LocalDB, then tried successfully to register a new user.

First, the project created its own membership database in the App_data folder, but for deployment reasons I wanted to change the database location, so I moved the database physical files from C:\MyProject\App_Data\ to C:\MyData and modified the related path in the web.config file. To ensure that the database is reachable by the SQL Server Express instance, I added my own user account with full access in the properties security tab, then successfully shown its data in SQL Server Management Studio.

Now, when I run the project, and click on the "log in" link, the debugger stops at LazyInitializer.EnsureInitialized and fails with an error; the inner exception of the error message says:

Database 'C:\MyProject\App_Data\aspnet-MyProject-20121206123456.mdf' already exists. Choose a different database name.
Cannot attach the file 'C:\MyData\aspnet-MyProject-20121206123456.mdf' as database 'aspnet-MyProject-20121206123456.mdf'

I checked all the project to find any different database connection settings but found nothing.

Within VS, when I use the server explorer to view the database tables data, I cannot find "show data" option when I right click on one of the displayed tables, when I go to C:\MyData\ folder to see the physical database files properties, in the security tab, I find that each time I run the project my account using full access was removed.

Also the browser is displaying the next Exception text:

The data provider. Net Framework requested was not found. It may not be installed.

C:\MyProject\Filters\InitializeSimpleMembershipAttribute.cs Ligne : 42

Ligne 40 :                 }
Ligne 41 : 
Ligne 42 :                     WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
Ligne 43 :                 }
Ligne 44 :                 catch (Exception ex)
Was it helpful?

Solution

It looks like a Visual Studio 2012 bug which doesn't recognize SQL Server 2012 Express instance. I have downloaded Microsoft WebMatrix2 and used it to load the website and could successfully log in using the moved membership database.

With this bug I've lost 2 days trying to find a solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top