Skip to content

How to copy your local MS SQL database to Azure

Mostly we develop our applications on local machine and then after completing it, we deploy it on the production server such as Azure cloud. Many time we deploy our application but we also need to deploy our database to the Azure MS SQL server. Deployment can include schema and table data both.

I went through such scenario where i developed my application in Asp.Net MVC 5 and published it on the Azure app services. I had a MS SQL 2012 database with some master data. For that i created a MS SQL database on Azure. When i published the app via Visual Studio 2015 community edition, it published the application on app services and updated the Azure database details in web.config file. But it doesn’t migrate the database from our local machine. So let’s see how we can upload our database to Azure.

First step is to configure end points of your Azure SQL server so that you connect to it from SQL server management studio. For this you have to visit SQL Server management portal. Here click on “Set server firewall” option.

set Firewall Azure option

Now you will get a screen like below to add your IP. Click on Add client IP button and it will autometically add you IP.

Add Firewall Setting for database in Azure

We are done with Azure side settings. Now generate script for your database, include schema and data.

After generating scripts now connect to your Azure hosted SQL database. You can get the server name from management portal, use username and password you set during creating the database. Now open the previously generated script and execute it. Make sure you remove using database line, if included or change it with Azure database name.

Thanks.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *