5

By default ASP.NET Identity user data is stored in an mdf file.

I want to store the data in a Sql database so that I changed the defaultconnection string in my web.config to my EF based connection:

 <add name="DefaultConnection" connectionString="metadata=res://*/Models.StartifyModel.csdl|res://*/Models.StartifyModel.ssdl|res://*/Models.StartifyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYPC\SQLEXPRESS;initial catalog=mydb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Now I am getting the error The entity type ApplicationUser is not part of the model for the current context. as soon as I want to register a user.

I use the default MVC5 project template of VS2013.

daniel
  • 34,281
  • 39
  • 104
  • 158

1 Answers1

7

Please try specify the connection string in the format:

<add name="DefaultConnection" connectionString="Data Source=127.0.0.1, 1433;Initial Catalog=YourDB;User Id=XXXX;Password=XXXXX;Asynchronous Processing=True;Encrypt=False;TrustServerCertificate=True;Persist Security Info=True" providerName="System.Data.SqlClient" />

And then make sure in Models/IdentityModels.cs you have

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }
Piotr Stulinski
  • 9,241
  • 8
  • 31
  • 46
  • 2
    I have still the same problem with this connection string. – daniel Oct 27 '13 at 18:10
  • I created a new project and now it works. I had some issue in the AccountController. – daniel Oct 27 '13 at 18:48
  • 2
    If you were to change to the non-EF connection string, as per your example, you will get `"Keyword not supported: 'data source'"` instead, as it is not a valid connection string for an EF connection (an EF database was specified in the question). This is not a correct answer for the question asked and will only confuse the issue. *Please revise or remove it.* – iCollect.it Ltd Nov 20 '13 at 11:33
  • That's the whole point. Switching to a normal data connection here gets this to work. You can still pull your DB tables into your EF data model and get at them through that context. – mlibby Jan 31 '16 at 19:27