Share via


How to Synchronize from SQL Azure to SQL Server using Visual Basic

When we introduced SQL Azure Data Sync, one of the primary goals was to reduce the complexity of getting started with synchronization using the Sync Framework.  Using the "SQL Azure Data Sync Tool for SQL Server" users can launch a wizard that configures synchronization from an existing SQL Server to a new SQL Azure database.  All of this is meant to give you a starting point for synchronization by automatically setting up the new tables in SQL Azure and build a synchronization relationship between the two databases.  In this wizard we also included an executable (SyncLocalSqlAzureDatabase.exe) that the SQL Agent process calls to execute synchronization on a scheduled basis.  But did you know that this executable is really just a very simple application that you can reproduce in about 10 lines of code?  But why would you want to do this when there is already a pre-built executable?  The best answers I think are in the case where you want to extend the funcitonality of this executable to get a better handle on events like conflicts and logging or even to embed the synchronization process into an existing application.  For example, by creating your own sync executable you can take the synchronization statistics that come back from the Sync Framework and store it to a custom logging table.  Or in the case of data conflicts you could choose to create your own conflict resolution method beyond the ones pre-built by the wizard.  Also using this technique you could add support for databases that do not have SQL Agent like SQL Express.

In part 2 of Hilton Giesenow's webcast series "How Do I: Integrate an Existing Application with SQL Azure?", he walks through the process of adding the synchronization components to a new VB.NET application and executes  synchronization between a SQL Server and SQL Azure database that had previously been created using the "SQL Azure Data Sync Tool for SQL Server" (part of SQL Azure Data Sync) in about 10 lines of code.  He also shows how you can get access to events like conflicts and sync statistics (like # of rows uploaded and downloaded) to get you started exteding your sync executable.

Thanks Hilton, great work once again!

Liam Cavanagh