The previous chapter introduces the concept of SQL azure Data sync. This chapter describes how to use data sync.
I. Preparations
Note: This chapter describes how to synchronize the local SQL Server 2008 R2 dB and SQL azure dB, so Install SQL Server 2008 R2 on the local machine first.
1. Use SQL Server Management studio to create databases and tables in the local SQL Server 2008 R2 dB.
-Database Name: employeeinfo
-Create Table student, T-SQL as follows
Create Table DBO. Student
(
Unikey Nvarchar ( 100 ) Not Null Primary Key Clustered ,
Value Nvarchar ( 100 ) Not Null
)
Go
Insert Into Student (unikey, value) Values
( ' FEFC201F-67E8-484F-A931-E620DCDA9D08 ' , N ' Xiao Zhao ' )
,( ' 6a987d4f-c9bf-4804-b5b5-e5223fc7ded7 ' , N ' Small money ' )
,( ' 0e467495-d139-4550-bbc1-610cd8305cd0 ' , N ' Sun ' )
,( ' B7BE884D-5650-460D-BE60-C1585D3CE1DE ' , N ' Xiao Li ' )
2. Create a new server on SQL Azure, located in "East Asia"
-Create a database named hubdb. The database type is "Web" and the maximum size is "1 GB"
-This database is used as the hub database of data sync.
3. Create on the same SQL azure Server
-The database name is azureemployeedb. The database type is "Web" and the maximum size is "1g"
-This database is used as the on cloud database.
Ii. Start data sync
1. log on to the Windows azure platform. (Process omitted)
2. Select "Data Synchronization" -- select "subscription" -- click "set"
3. Agree to the Terms of Use
4. Select subscription
5. Select a region. Select "East Asia ". (Hong Kong's data centers are closest to the Chinese mainland and are fast)
6. Select "synchronization group" under the subscription, and then select "CREATE"
7. Name the synchronization group "myfirstgroup"
8. Click "SQL Server database" in "internal deployment"
9. "Add database to synchronization group" is displayed. Because this is the first time we use it, select "Add a new SQL Server database to synchronization group ", select "two-way" for synchronization ". Then select "Next"
10. A new database window appears. You can use the local SQL Server to communicate with the hub dB.
11. To ensure communication security, we must install the data sync agent on the local SQL server host. We have not installed the agent before, so click "Install.
12. A new ie window will pop up. Go to the download page of msdn, select a large file, and click Download.
13. After the download is complete, install Microsoft SQL azure Data sync agent Preview
Enter the username (domain \ USERNAME) for logging on to Windows in user name. Note: This user must be able to access the network.
Enter the password for logging on to Windows in Password
14. After installing the agent, we name the local agent "localtocloudagent"
15. in step 3, press "generate proxy key" to generate a set of keys immediately. This key will be used later. Select "copy" to copy the key content to the clipboard.
16. Next we will go to "add database to synchronization group ".
17. First, follow Step 1 to start the "Microsoft SQL azure Data sync agent preview" installed on the local machine, and then click "Submit agent key"
19. In the pop-up window, copy the content we copied in the generated agent key before. Then select "OK"
20. Click "register" in "Microsoft SQL azure Data sync agent preview"
Select "access SQL Server in Windows"
21. Then we can see that the SQL server of the local machine has been added.
22. Click "Get database list" and select the local SQL Server database.
23. In this way, we can deploy the local SQL Server to "internal deployment ".
24. Then we add the hub database (Synchronization Center)
25. Add the hub dB we have created in SQL azure.
26. Select "Edit dataset" on the right"
27. You can browse the local SQL Server database and select the database table name and field to be synchronized.
28. In the configuration, we can select the interval at which data synchronization is executed. Here I select "5 minutes"
29. Then we can synchronize the database content of the local SQL Server to the Hub database.
29. In the same way, we can use the hub database to synchronize the local SQL Server to the cloud database.