合并两个ASP.NET成员资格数据库

我必须将两个ASP.NET成员资格数据库与相关的角色和配置文件表合并.两个数据库具有相同的角色和配置文件结构.他们使用内置的提供程序(SqlMembershipProvider和朋友).可以重复.

你有推荐给我吗?有没有工具可以做到这一点?如果不是:您是否可以推荐使用成员资格API,或者更容易使用SQL.

更新

这是我最终用来传输会员资料的脚本.

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)

按原样提供.不检查重复的电子邮件.不保证这在更复杂的情况下有效.

最佳答案 我不知道有任何工具可以做到这一点,但架构非常简单,因此在SQL中执行它是一项非常简单的工作.无论如何所有的键都是GUID,所以应该没有问题.

如果应用了唯一的电子邮件地址规则,显然您需要检查user_name字段中是否有重复项和电子邮件地址.但如果两个数据库中的角色相同,那么您真正感兴趣的就是用户.一旦你完成了它,只需要在aspnet_Users和aspnet_UsersInRoles中更新RoleId和ApplicationId.

点赞