I'm trying to use my own SQL Server database to store the user permissions.
I initialize the UserStore with my context like this (I tried with the default constructor also)
UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>(new DbEpicerieEntities()));
Then I created an empty database and generated the data model for entity.
Then I changed the web config for my connection
<connectionStrings>
<add name="DefaultConnection" connectionString="metadata=res://*/Models.EpicerieModel.csdl|res://*/Models.EpicerieModel.ssdl|res://*/Models.EpicerieModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=DbEpicerie;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
But it doesn't work. If I try to register a user, after
IdentityResult result = await UserManager.CreateAsync(user);
it will call
protected override void Dispose(bool disposing)
{
if (disposing)
{
UserManager.Dispose();
}
base.Dispose(disposing);
}
I tried to use a database with tables already made, but I have the same result.
I tried to change the connection name for DefaultConnection
but no success.
I tried the recommendations on that question and I changed DbContext
to IdentityDbContext<IdentityUser>
public partial class DbEpicerieEntities : IdentityDbContext<IdentityUser>
{
public DbEpicerieEntities()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
}
but I have the same problem.
I don't know if the EntityFramework setting in the web config could be the problem
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Any ideas why it doesn't work?
Thank you