0

Having a ASP.NET webforms application, I use aspnetdb database created in the SQL server.

When migrating to Azure, is there any way to replace the aspnetdb database by something else so that it would not eat one database from the Azure SQL Database component? Or is the specific database supported somehow as the part of the App Services (Azure component)?

What is the typical replacement of the form of the aspnetdb datababase when working with Azure App Services?

Update: In the original application, I am using two databases in MS SQL Standard Ed. -- typically like company_users (this is the name for the aspnetdb) and company_app for the application tables. I usually create the company_users via a small external application that creates the database, the roles, and also the initial users -- see the shortened code below.

So, it probably would be more straightforward to migrate the two databases to Azure SQL Database, and to use it the same way. On the other hand, one have to pay for the Azure SQL based on the number of databases. While it is fine for the company_app, the company_users is rather small and probably worth to be replaced by something cheaper. This is the motivation for replacing the one for authentication/authorization part of the framework (aspnetdb alias company_users) by something else that would not eat one SQL database.

The shortened source code of my 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
}
pepr
  • 20,112
  • 15
  • 76
  • 139

1 Answers1

1

How to replace the App_Data\aspnetdb.mdf when migrating to MS Azure?

Based on my understanding, you are using SQL Server LocalDB. Azure Web Apps do not install the SQL Server Express. I assume that you could migrate your LocalDB database to SQL Server or SQL Azure. Here is a similar issue, you could refer to it. In order to migrate your database to Azure SQL Database or SQL Server, you could follow the approaches below:

  • Use SQL Server Management Studio (SSMS), right click your database, then choose "Tasks > Export Data", configure the Data Source and Destination. More details, you could refer to here.

  • Use the SSIS Import and Export Wizard from Visual Studio, more details you could refer to here.

Moreover, for creating Azure SQL database, you could follow here. Additionally, if you are using Entity Framework Model First or Entity Framework Code First, you could change your connection string and regenerate your database easily.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • Thanks, Bruce. I have added the Update part to the question to explain the motivation. I am very new to Azure. I can imagine there may be alternative solution when using the Azure App services. So, actually, I do not insist on creating the SQL database. I need a cheaper (money) solution for the same task, if possible. Do you have any experience with the mentioned SQL compact for the case? – pepr Jan 17 '18 at 08:53
  • Per my understanding, you could leverage [Azure Table storage](https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-overview) for a cheaper choice. You could follow [here](https://learn.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet) for getting started with Azure Table storage. Moreover, you could use [Azure Storage Explorer](https://learn.microsoft.com/en-us/azure/vs-azure-tools-storage-manage-with-storage-explorer) to manage your table storage. – Bruce Chen Jan 17 '18 at 09:02