سؤال

I am developing a windows application which is using local database. I want to add a function to sync all local data to the sql azure.

Currently I used following code. It enabled me to sync one particular table successfully., here is "Author_Master"

 string sqlazureConnectionString = "XXXX";
 string sqllocalConnectionString = "Server=localhost;Database=Enh_Branchwise_Master_Bookshop;Trusted_Connection=True";

        using (SqlConnection serverCon = new SqlConnection(sqlazureConnectionString))
        using (SqlConnection clientCon = new SqlConnection(sqllocalConnectionString))
        {
            var provider1 = new SqlSyncProvider("scope1", serverCon);
            var provider2 = new SqlSyncProvider("scope1", clientCon);

            prepareServer(provider1);
            prepareClinet(provider2, serverCon);
            SyncOrchestrator sync = new SyncOrchestrator();
            sync.LocalProvider = provider1;
            sync.RemoteProvider = provider2;

            sync.Synchronize();

        }

And following methods also.

 private static void prepareServer(SqlSyncProvider provider)
    {
        SqlConnection connection = (SqlConnection)provider.Connection;
        SqlSyncScopeProvisioning config = new SqlSyncScopeProvisioning(connection);

        if (!config.ScopeExists(provider.ScopeName))
        {
            DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(provider.ScopeName);
            scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Author_Master", connection));
            config.PopulateFromScopeDescription(scopeDesc);
            config.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
            config.Apply();
        }
    }

    private static void prepareClinet(SqlSyncProvider provider, SqlConnection sourceConnection)
    {
        SqlConnection connection = (SqlConnection)provider.Connection;
        SqlSyncScopeProvisioning config = new SqlSyncScopeProvisioning(connection);

        if (!config.ScopeExists(provider.ScopeName))
        {
            DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(provider.ScopeName);
            scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Author_Master", sourceConnection));
            config.PopulateFromScopeDescription(scopeDesc);
            config.Apply();
        }
    }

My question : Is there any way to sync all the tables in the database at once, without adding one by one table .

My both Databases have the same schema. Please give some suggestions,

هل كانت مفيدة؟

المحلول 3

  Dim clientProvision As SqlSyncScopeProvisioning = New SqlSyncScopeProvisioning(clientCon, syncScope)


                            If Not (clientProvision.ScopeExists("Scope_" + tableName)) Then
                                clientProvision.Apply()
                            End If

                            Dim serverProvision As SqlSyncScopeProvisioning = New SqlSyncScopeProvisioning(serverCon, syncScope)

                            If Not (serverProvision.ScopeExists("Scope_" + tableName)) Then
                                serverProvision.Apply()
                            End If

                            Dim syncOrchestrator As New SyncOrchestrator()

                            ' Create provider for SQL Server
                            Dim clientProvider As New SqlSyncProvider("Scope_" + tableName, clientCon)

                            ' Set the command timeout and maximum transaction size for the SQL Azure provider.
                            Dim serverProvider As New SqlSyncProvider("Scope_" + tableName, serverCon)

                            ' Set Local provider of SyncOrchestrator to the onPremise provider
                            syncOrchestrator.LocalProvider = clientProvider

                            ' Set Remote provider of SyncOrchestrator to the azureProvider provider 
                            syncOrchestrator.RemoteProvider = serverProvider

                            ' Set the direction of SyncOrchestrator session to Upload and Download
                            syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload


                            'Dim thread As New Threading.Thread(Sub() ShowStatistics(syncOrchestrator.Synchronize(), tableName))
                            'thread.Start()
                            ShowStatistics(syncOrchestrator.Synchronize(), tableName)

نصائح أخرى

You can use SQL Data Sync Tool.

SQL Data Sync is a feature of Windows Azure SQL Database.

With SQL Data Sync you can synchronize selected data through a Windows Azure SQL Database instance.

SQL Data Sync supports synchronizations within or across Windows Azure data centers.

SQL Data Sync also supports hybrid configurations of SQL Database instances and on-premises SQL Server databases.

The SQL Data Sync service is free.

For more details check ScottGu's Blog Post under "SQL Data Sync" sub topic.

I hope this will help to you.

if you're using Sync Framework, you have to tell it explicitly which tables (or even columns) to actually sync.

You can use SQL Database Migration Wizard (SQLAzureMW) for that.

It is an open source application.

You can use it to migrate your SQL database to and from Windows Azure SQL Database.

SQLAzureMW has a user interactive wizard that walks a person through the analysis / migration process.

For get more details about SQL Database Migration Wizard

I hope this will help to you.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top