gpt4 book ai didi

asp.net - 将一个站点的 asp.net 成员资格记录从一台 SQL Server 传输到另一台

转载 作者:行者123 更新时间:2023-12-02 16:20:08 25 4
gpt4 key购买 nike

我需要将一个网站的 asp.net 成员(member)数据从包含多个网站条目的 SQL Server 数据库传输到另一台 SQL Server。

我正在寻找一些现有/已知的方法来执行此操作?我尝试了 Web Deploy 实用程序,但找不到任何传输数据库记录的方法。

任何帮助将不胜感激。

谢谢。

最佳答案

ASP.NET 成员(member)数据库只是一个“普通”SQL Server 数据库,因此问题实际上是“如何将 SQL Server 数据库从一台服务器传输到另一台服务器,仅使用其中包含的部分数据”。

1)由于旧服务器上的数据库包含多个站点的成员(member)信息,因此您必须知道如何在数据库中查找“您的”站点(您要转移的站点)的数据。

我在 this tutorial 中找到了有关 ASP.NET 成员资格数据库架构的信息。在 ASP.NET 网站上。
向下滚动到“第 3 步:查看架构的核心表”。
关键信息是这样的,尤其是我加粗的句子:

The aspnet_Applications table is what defines these partitions. Each application that uses the database to store user account information is represented by a row in this table. The aspnet_Applications table has four columns: ApplicationId, ApplicationName, LoweredApplicationName, and Description. ApplicationId is of type uniqueidentifier and is the table's primary key; ApplicationName provides a unique human-friendly name for each application.

The other Membership- and Role-related tables link back to the ApplicationId field in aspnet_Applications. For example, the aspnet_Users table, which contains a record for each user account, has an ApplicationId foreign key field; ditto for the aspnet_Roles table. The ApplicationId field in these tables specifies the application partition the user account or role belongs to.

简而言之:您必须在aspnet_Applications中找到您要转移的网站。表中,从 ApplicationId 中获取 ID列并查找具有相同 ApplicationId 的所有行在所有其他表中。

2) 既然您知道如何在数据库中查找站点的数据,那么您可以将数据移动到新服务器。这不是 ASP.NET 特有的,它只是简单的 SQL Server 内容 - 您只需在新服务器上创建相同的数据库,但仅使用您站点的数据。

我可以想到两种方法来做到这一点:

方法一:

  1. Backup旧服务器上的整个数据库
  2. Restore此备份在新服务器上
  3. 现在您在新服务器上拥有了完整的数据库,但它包含所有网站的数据,而不仅仅是您想要的网站
    --> 您必须从新服务器上的数据库中删除所有其他站点的数据。
    最简单的方法是使用 SQL - 只需对数据库中的每个表执行此操作:
    delete from aspnet_Users where ApplicationID <> 'X'
    (其中 XApplicationID 表中您网站的 aspnet_Applications)

方式2:

  1. 在新服务器上创建一个新的空成员(member)数据库
  2. 将旧 SQL Server 设置为 Linked Server在新的 SQL Server 中
    (这使您能够在新服务器上运行 SQL,从旧服务器中选择数据)
  3. 将您网站的数据从旧服务器中的每个表复制到新服务器。只需对每个表执行以下 SQL:
    insert into aspnet_Users<br/>
    select * from [Name_of_old_server].[Name_of_old_database].dbo.aspnet_Users<br/>
    where ApplicationID = 'X'

    (其中 XApplicationID 表中您网站的 aspnet_Applications)
  4. 现在您可以再次删除链接服务器(您在第 2 步中创建的) - 它只是为了传输一次数据。

关于asp.net - 将一个站点的 asp.net 成员资格记录从一台 SQL Server 传输到另一台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9239401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com