Merging Two ASP.NET Membership Databases

I need to combine two ASP.NET membership databases with the corresponding roles and profile tables. Both databases have the same role and profile structure. They use built-in providers (SqlMembershipProvider and friends). Duplicates are possible.

Do you have any recommendations for me? Is there a tool for this? If not: can you recommend using the membership API or is it easier to use SQL.

Update

Here is the script that I finally used to transfer membership data.

insert into targetMembershipDatabase.dbo.aspnet_users select * from sourceMembershipDatabase.dbo.aspnet_users where username not in (select username from targetMembershipDatabase.dbo.aspnet_users) insert into targetMembershipDatabase.dbo.aspnet_membership select * from sourceMembershipDatabase.dbo.aspnet_membership where userid in (select userid from targetMembershipDatabase.dbo.aspnet_users) and not userid in (select userid from targetMembershipDatabase.dbo.aspnet_membership) insert into targetMembershipDatabase.dbo.aspnet_profile select * from sourceMembershipDatabase.dbo.aspnet_profile where userid in (select userid from targetMembershipDatabase.dbo.aspnet_users) and not userid in (select userid from targetMembershipDatabase.dbo.aspnet_profile) insert into targetMembershipDatabase.dbo.aspnet_usersinroles select * from sourceMembershipDatabase.dbo.aspnet_usersinroles where userid in (select userid from targetMembershipDatabase.dbo.aspnet_users) and not userid in (select userid from targetMembershipDatabase.dbo.aspnet_usersinroles) 

Provided as is. Do not check duplicate letters. There is no guarantee that this will work in a more complex scenario.

+4
source share
2 answers

I don’t know about any tool that will do this, but the schema is quite simple, so just doing it is quite simple in SQL. All GUID keys are in any case, so there should be no problems.

Obviously, you need to check the user_name field for duplicates and email addresses if a unique email address rule applies. But if the roles in both databases are the same, then all that you are really interested in is users. Once you get them, it will just be updating RoleId and ApplicationId in aspnet_Users and aspnet_UsersInRoles .

+2
source

I am currently using the same database for three different applications. Each of them has its own ApplicationID , and nothing special has been happening for me for 2 years now. even similar letters are available (because sql checks the ApplicationID , and each application has only one mail), so I don’t think you need to consider something special

Just create a script from the data and run in your main database so that this does not replace the table schema.

0
source

Source: https://habr.com/ru/post/1346872/


All Articles