Click here to Skip to main content
15,886,067 members
Articles / Database Development / SQL Server / SQL Server 2014

Synchronization between local and Azure SQL DB using SLQ Management Studio "Export Data..."

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
17 Mar 2015CPOL4 min read 18.1K   3   4
This article explains how to merge your local SQL DB content to Azure DB from scratch

Introduction

Here I'm going to show you step-by-step instructions how to create Local and Azure databases and do synchronization between them. This article is based on a real project activity that I performed.

Steps

1. First of all let's create Local DB. For this purpose I run SQL Management Studio, right click on Databases and Select  "New database…"  

 Image 1

2. Enter DB name and press OK. In my case DB name is iSpeakDB:

Image 2

3. In my case I need to access this DB using my applications, so I also went to Security->Logins and created a user for accessing my DB and mapped it to iSpeakDB. If you don't plan to fill your SQL data with some other tools, you can skip this step

4. Fourth step for me is to create data base tables. I have SQL scripts created for this. And run a query on iSpeakDB. Below is a simplest script example that you can use to create a table:

USE [iSpeakDB]

GO

CREATE TABLE [dbo].[tblUser](

[UserID] [nchar](100) NOT NULL,

[ExpirationDate] [datetime] NULL,

[OperationSystem] [nchar](100) NULL,

[Country] [nchar](100) NULL,

)

GO

5. Now when our data base structure is ready and created it is time to populate it with data. In my case I use utility that we build and that fill my DB with data.

6. When data is ready and is on local DB it is time to switch to Azure and create our DB schema there. I connect to my Azure portal, created there SQL DB called iSpeakDB in my case. Next step I opened management portal for DB and selected "New Query". There I run similar script as for local DB but with one additional string. See screenshot below:

Image 3

As you can see I used CREATE CLUSTERED INDEX command to create the index for table. The problem is that Azure DB has its own limitations and requirements and it doesn't support tables without clustered indexes. You can read more about Azure limitations here:

https://msdn.microsoft.com/en-us/library/azure/ee336245.aspx

7. I didn't find any way how to see if my tables were created correctly and I had to run simple select query on each table to see if all columns appear and table is correct

8. Now when tables in cloud are ready and I have same DB as local I need to sync between two databases. For this purpose I use SQL Server Management studio. Navigate to your DB and by right click select Tasks->Export Data

Image 4

9. Click next in wizard that appears. Now you're in "Choose Data Source" page. You need to make sure that proper server, DB and authentication mode is selected. If everything is correct and data is related to DB that you want to transfer to Azure, click Next.

10. Next page in wizard is named "Choose Destination". Here we have sensitive moment. You should choose: ".NET Framework Data Provider for SqlServer". Now in list of possible parameter you should find Data->Connection string and copy there connection string that you use by your Azure service to access Azure DB. I copied connection string from SQL Management portal and inserted it to property field called "ConnectionString" it looks like this:

Server=<your server>,1433;Database=<your DB>;User ID=<your user>;Password=<your password>;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

 

Bold-italic things should be replaced by your data.

One more thing that we need to do before pressing Next button is to change value of "TrustedServerCertificate" property to "True"

11. Clicking "Next" navigates us to menu where we should set radio button for "Copy data from one or more tables or views" and press "Next"

12. On the next page named "Select Source Tables and Views" you should select tables that you want to synchronize and click Next

13. In next page you can save "SSIS Package" that you can later restore or run data transfer immediately. I use "Run immediately" and press "Next" and "Finish" on next page to run data transfer

14. When data transfer finished you will see results as they shown below:

Image 5

15. You may receive error while connecting to Azure DB. One of possible fixes is to go to Azure management portal and add current IP to list of IPs that can access DB for data modifications. Open there DB  page and go to "Set up Windows Azure firewall rules for this IP address".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Ukraine Ukraine
Working on different projects and technologies from web to low level core programming, from scripting languages to C++. With all this stuff my personal opinion is that C#,.NET and Microsoft environment is the best thing programmer may have. Basing on it I prefer to publish only about my favorite technologies that are .NET and Azure now.

P.S. Looking for partnership and cooperation in outsourcing.

Comments and Discussions

 
QuestionWhere is the Synchronization process Pin
m.munier21-Mar-15 22:00
m.munier21-Mar-15 22:00 
AnswerRe: Where is the Synchronization process Pin
Sergey Kizyan25-Mar-15 22:23
professionalSergey Kizyan25-Mar-15 22:23 
QuestionWorks for all SQL databases Pin
Rene Balvert18-Mar-15 7:57
Rene Balvert18-Mar-15 7:57 
AnswerRe: Works for all SQL databases Pin
Sergey Kizyan18-Mar-15 23:06
professionalSergey Kizyan18-Mar-15 23:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.