Joseph Michael Pesch
VP Programming

Issue with ASP.Net Identity from Default Local File System Database to SQL Server Based Database

by 22. December 2014 10:12

I created a new MVC 5 web application with the "Individual User Account" option that configures the ASP.Net Identity model.  By default this uses Entity Framework Code First model with a local file system database created in the local App_Data folder.  I tried moving this to an actual SQL Server database location by creating the five dbo.aspnet_... tables and changing the web.config to point to the new location.  However, in doing so I received the error below.  Turns out to solve this I just needed to change the connection string in the web.config from the Entity Framework style to the basic style (see old vs. new connection strings below).


    <addname="NewSimpleConnection"connectionString="Data Source=SERVER_NAME_HERE;initial catalog=DB_NAME_HERE;user id=USER_ID_HERE;password=PASSWORD_HERE;Integrated Security=False"providerName="System.Data.SqlClient" />

    <addname="OldEtityFConnection"connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=SERVER_NAME_HERE;initial catalog=DB_NAME_HERE;user id=USER_ID_HERE;password=PASSWORD_HERE;MultipleActiveResultSets=True;App=EntityFramework&quot;"providerName="System.Data.EntityClient" />


Server Error in '/' Application.


Unable to load the specified metadata resource.

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.Entity.Core.MetadataException: Unable to load the specified metadata resource.

Source Error:


Line 114:      {
Line 115:        var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
Line 116:        IdentityResult result = await UserManager.CreateAsync(user, model.Password);
Line 117:        if (result.Succeeded)
Line 118:        {


ASP.Net | C# | SQL Server