Search code examples
c#sqlmodel-view-controllersimplemembershipuser-roles

Roles.AddUsersToRoles() requires IDENTITY_INSERT is ON


Migrated from LocalDB to SQL Server. Trying to add role to user:

if (!Roles.GetRolesForUser("admin").Contains("Admin"))
                Roles.AddUsersToRoles(new[] { "admin" }, new[] { "Admin" });

and catching this:

An explicit value for the identity column in table 'webpages_UsersInRoles' can only be specified when a column list is used and IDENTITY_INSERT is ON.


Solution

  • Solution is simple: check your webpages_UsersInRoles fields. Identity Specification on all fields MUST BE disabled.