Publish ASP.NET project with local data on Azure - asp.net

I'm quite new to ASP.NET and I encountered a problem when publishing my project to Azure. After configuring the connectionStrings in Web.config, I have successfully uploaded my local database structure to Azure. However, all tables on Azure are now empty, without any local data. So how can I upload both the database structure as well as the data in it? Thanks in advance.

To migrate an existing SQL Server database to Azure SQL Database you can export the schema as a TSQL script and then execute that script against Microsoft Azure SQL Database as follows:
1.Open SQL Server Management Studio and connect to an instance of the Database Engine.
In Object Explorer, right click a database to open a menu, select Tasks…, and then select Generate Scripts.
2.Choose objects to export.
3.Set scripting options. You have the options to save the script to file, clipboard, new query window; or publish it to a web service.
4.Set advanced scripting options.
You can also set the Types of data to script to one of the following based on your requirements: Schema only, Data only, Schema and data.
5.After the script is created, you have the option to modify the script before running the script against an Azure SQL Database to transfer the database.
You can now run this script on your Azure SQL Database.
For more details, you could refer to this article.

You have to create a post deployment script. If the tables are created just fine on your azure application, then you must define what default data they will have. So in your post deployment script you will insert the data you want.

Related

Is it possible to easily migrate data from light SQL Server Express to Azure with a dacpac file?

I'm currently trying to deploy a website with Azure which I did following these steps
https://learn.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-aspnet-core-ef-step-05?view=vs-2019#publish-to-azure-app-service
however the data from the database didn't get saved, like it did in the video. I think this may be because I have 2 data contexts; one for users and one for general app models.
I believe I have to figure out how to migrate my data from SQL Server Express provided by Entity Framework to Azure.
It seems like it should be doable from this link
but then this one makes it sound like you need a .bak file.
Just want to know if my Visual Studio data can easily transferred to Azure this way. would it be easier to publish my "data tier application" or extract and copy what I need to azure. Kind of overwhelmed at all the documentation trying to find the easiest way the small amount of data for my test website.
How to migrate my data from SQL Server Express provided by Entity Framework to Azure?
No you can not do that, import and export feature is not available with SQL Server Express. You can reference this link: Limitations of SQL Server Express.
As you posted the screen shoot, no function can help you migrate the database to Azure.
So if you really want migrate the database from local SQL Server to Azure, you'd better using the Microsoft SQL Server Management Studio(SSMS). There are so many ways, such as:
Migrate on-premises SQL Server or SQL Server on Azure VMs to Azure SQL Database using the Data Migration Assistant
Tutorial: Migrate SQL Server to a single database or pooled database in Azure SQL Database offline using DMS
Copy data to and from SQL Server by using Azure Data Factory
Migrating SQL Database to Azure SQL Database using SSMS Export/Import
If you are first time to migrate, we suggest to you use the Azure Data Migration Assistant as Alberto Morillo said.
Hope this helps.
Before trying to migrate the database to Azure you need to first verify the database and its objects are compatible to Azure SQL Database. If you don't do that the migration may fail.
My suggestion is to use Azure Data Migration Assistant (DMA) to perform an assessment of your database and make sure there are no blocking points that can make the migration not possible. Make adjustments based on the report generated by the DMA tool and then use any migration method (including extracting\importing a Data-tier Application) to migrate your database to Azure SQL Database. DMA can also migrate your database to Azure SQL Database and for me is the easiest way to do it.
About restoring a native backup to Azure SQL Database, that is not possible. You can export your database as bacpac and then import it to Azure SQL Database, or you can use DMA or Data Migration Service to migrate your databases to Azure SQL Database.
Adding to what is already said . You can dump all the data in txt or csv file and put that in the local drive . In Azure we have the Azure data factory (ADF) , which has a copy activity , this is very powerful and looks like will be good for your scenario . As mentioned before the data types are the key . You will have to install something called integrated Runtime ( IR ) and it should work .

sql query or command tool to append mdf file to windows azure SQL DB

I'm trying to migrate my ASP.NET MVC app to Windows Azure, but on my code I have a module that imports data from a ".mdf" file hosted on the server to my SQL-Server DB using the SQL-Server "sp_attach_db" and "sp_dettach_db" commands and then referencing tables with {databasename}.{owner}.{table}, now with Azure it is not possible to do it this way but I can't figure out a workaround, any idea?
Thank you
Added: Conclusion
It seems not possible to attach "on the fly" a DB to SQL azure and share data with the others databases

Exporting ASPNETDB.MDF to an external database

ASP.Net 4.0/C#/MSSQL/Microsoft SQL Server Management Studio
Hey I am now at the stage where I want to move a project to a live server
Now I want to move the tables from the ASPNETDB file in the App_Data folder
to the server.
I have used the Aspnet_regsql.exe tool to successfully generate the following tables
on my shared hosted server
dbo.aspnet_Applications
dbo.aspnet_Membership
dbo.aspnet_Paths
dbo.aspnet_PersonalizationAllUsers
dbo.aspnet_PersonalizationPerUser
dbo.aspnet_Profile
dbo.aspnet_Roles
dbo.aspnet_SchemaVersions
dbo.aspnet_Users
dbo.aspnet_UsersInRoles
dbo.aspnet_WebEvent_Events
Now what is the next step to essentially copy the tables from ASPNETDB.MDF
to these tables on the server?
Many thanks =)
What version of SQL server have you got?
If you can open the database locally in SQL Management Studio you can just use Generate Scripts that you can then simply open and run on your production server. It has the option to copy
Data
Schema
Both
So you can start with an empty database on Production and copy both the data and schema at once with a single .sql file and you'll be good to go.
You can use the export data feature from the management studio to migrate the data from the msf file to the live dtabse.
You are really better off putting all the membership etc. tables, views and stored procs into the main database for your production application. You can do this with the Database Publishing Wizard, which will create a script to recreate everything including all the data. No need to use two separate databases.
Alternatively, one can run this exe to copy empty tables from ASPNETDB.mdf to external SQL server.
drive:\WINDOWS\Microsoft.NET\Framework\versionNumber\aspnet_regsql.exe

Where to start when uploading a SQL Server database to a web server

Here's another question on my lips.
My website uses a database which was created in SQL Server 2008 R2 Enterprise Edition. Where do I start when I plan to upload the database to the web server? My Website will require this database. Should I send the Scripts which created the database to the Staff of the web server so they can Recreate my database, or should I detach my database and place it in the App Data folder, followed by an update of my Connection strings to reference the detached database?
Another thing I fear is the Database version. Will my Database connection break on the web server because of the "Version of database is 655 and cannot be downgraded to 612" Error? and If yes, How would I prevent that?
The Best way would be to
1: Send them the scripts, let them run it on their side, they should then be able to provide you with server name, database name user id etc.
2: Create a .bak backup file of the database and send that to them and ask them to restore it for you, this way you save a lot of the hassle of creating scripts and you also ensure that the database is like you want it and you know they haven't made a mess of restoring the scripts.
You can also ask them if they don't have some sort of management console where you can upload the database yourself
My suggestion would be to create a back up of the SQL database, and give that to the web server admin to restore on their server. This will mean that you can guarantee that you will get no problems with the structure, and you should simply have to change the connection string in your Web.Config (assuming that you have always created your connections in code based on the connection string in the web.config), to contain a user name and password that your web server admin gives you (if it's a back up and restore of your db, assuming you use SQL authentication, the new db on the web server will have the same users anyway).
Some options;
If you have access via Management Studio just use the import/export tools or the Copy Database Wizard
If the remote sql server can read from one of the site directories you have access to upload a .bak backup and restore, or upload the database files proper and use one of the sp_attach* procedures
Script the database (including data) upload the individual files & create a quick and dirty script that will execute them.

How do I migrate a SQL MDF File to a production SQL Server? (ASP.NET)

I have an ASP.NET project that also uses a SQL MDF File. My target server is SQL 2008R2 or SQL Azure.
I would like to know what deployment options I have as I migrate from DEV to PROD. In case it matters I'm not under any regulation to maintain PII or similarly private data.
How do I move my test schema and perhaps data to production?
You can move the entire database, including the data by attaching the MDF file to the new SQL server. Otherwise you can select all objects and generate CREATE scripts to copy the schema over.
Yes, you can attach to the MDF file directly, or do a backup / restore to get it over to SQL Server 2008.
I haven't played with SQL Azure... From what little I've heard I think you might be stuck scripting the data as durilai suggested (last I heard we're not allowed to do backups / restores for SQL Azure).
In SQL Server Management tools, right click on the database and click 'Script Database As' to create an SQL script for your database. You can also do something similar at the table level if you want the data.

Resources