【问题标题】:How to replace the App_Data\aspnetdb.mdf when migrating to MS Azure?迁移到 MS Azure 时如何替换 App_Data\aspnetdb.mdf?
【发布时间】:2018-01-16 21:11:37
【问题描述】:

拥有一个 ASP.NET webforms 应用程序,我使用在 SQL 服务器中创建的 aspnetdb 数据库。

迁移到 Azure 时,是否有任何方法可以将 aspnetdb 数据库替换为其他东西,这样它就不会占用 Azure SQL 数据库组件中的一个数据库?还是以某种方式支持特定数据库作为应用服务(Azure 组件)的一部分?

在使用 Azure 应用服务时,aspnetdb 数据库的典型替换形式是什么?

更新:在原始应用程序中,我在 MS SQL 标准版中使用了两个数据库。 -- 通常像company_users(这是aspnetdb 的名称)和应用程序表的company_app。我通常通过一个小型外部应用程序创建company_users,该应用程序创建数据库、角色以及初始用户——请参阅下面的缩短代码。

因此,将这两个数据库迁移到 Azure SQL 数据库并以相同的方式使用它可能会更直接。另一方面,必须根据数据库的数量为 Azure SQL 付费。虽然company_app 很好,但company_users 相当小,可能值得用更便宜的东西代替。这是将框架的身份验证/授权部分(aspnetdb 别名 company_users)替换为不会占用一个 SQL 数据库的其他东西的动机。

我的InitUsers.exe的缩短源代码:

// ... get the configuration information to be used for...
SqlServices.Install(SQLServerName,
                    SQLServerUser, SQLServerPassword,
                    ASPNETdbName, SqlFeatures.All);
// ... and the roles in the loop...
SqlRoleProvider roleProvider = AModule.GetRoleProvider();
string[] roles = { "admin", "poweruser", /* ... */ };
foreach (var role in roles) {
    if (!roleProvider.RoleExists(role))
        roleProvider.CreateRole(role);
}
// ... and the initial users...
List<string[]> userList = new List<string[]> {
    //      0       1                 2        3        4       5       6
    //      login,  email,            roles,   first,   last    tit.,   phone
    new[] { "nemo", "nemo@ocean.org", "admin", "Nihil", "Nemo", "cpt.", "123 456 789"}
};
foreach (var info in userList) {
    string login = info[0];
    string password = ...;
    string email = info[1];
    string[] rolenames = info[2].Split();
    string first = info[3];
    string last = info[4];
    string title = info[5];
    string phone = info[6];

    AModule.MakeUser(login, password, email, rolenames,
                     first, last, title, phone,
                     true);     // isApproved
}

【问题讨论】:

    标签: azure-web-app-service aspnetdb


    【解决方案1】:

    迁移到 MS Azure 时如何替换 App_Data\aspnetdb.mdf?

    根据我的理解,您使用的是 SQL Server LocalDB。 Azure Web Apps 不安装 SQL Server Express。我假设您可以将 LocalDB 数据库迁移到 SQL Server 或 SQL Azure。这里有一个类似的issue,你可以参考一下。为了将您的数据库迁移到 Azure SQL 数据库或 SQL Server,您可以遵循以下方法:

    • 使用 SQL Server Management Studio (SSMS),右键单击您的数据库,然后选择“任务 > 导出数据”,配置数据源和目标。更多详情,您可以参考here

    • 使用 Visual Studio 中的 SSIS 导入和导出向导,更多详细信息您可以参考here

    此外,创建 Azure SQL 数据库,您可以关注here。此外,如果您使用Entity Framework Model FirstEntity Framework Code First,您可以轻松更改连接字符串并重新生成数据库。

    【讨论】:

    • 谢谢,布鲁斯。我已将更新部分添加到问题中以解释动机。我对 Azure 很陌生。我可以想象在使用 Azure App 服务时可能会有替代解决方案。所以,实际上,我并不坚持创建 SQL 数据库。如果可能的话,我需要一个更便宜的(金钱)解决方案来完成相同的任务。您对本案提到的 SQL compact 有任何经验吗?
    • 据我了解,您可以利用Azure Table storage 获得更便宜的选择。您可以关注 here 以开始使用 Azure 表存储。此外,您可以使用Azure Storage Explorer 来管理您的表存储。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 2017-08-15
    相关资源
    最近更新 更多