2

我正在开发一个使用本地数据库的 Windows 应用程序。我想添加一个函数来将所有本地数据同步到 sql azure。

目前我使用以下代码。它使我能够成功同步一个特定的表。这里是“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();

        }

还有以下方法。

 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();
        }
    }

我的问题:有什么方法可以一次同步数据库中的所有表,而无需逐个添加表。

我的两个数据库具有相同的架构。请给些建议,

4

4 回答 4

2

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.

于 2012-12-26T14:28:32.763 回答
1

如果您使用的是 Sync Framework,则必须明确告诉它实际同步哪些表(甚至列)。

于 2012-12-26T11:41:00.127 回答
0
  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)
于 2014-01-06T17:03:39.413 回答
-1

您可以为此使用SQL 数据库迁移向导(SQLAzureMW)。

它是一个开源应用程序。

您可以使用它在 Windows Azure SQL 数据库之间迁移您的 SQL 数据库。

SQLAzureMW 有一个用户交互向导,可以引导用户完成分析/迁移过程。

获取有关SQL 数据库迁移向导的更多详细信息

我希望这对你有帮助。

于 2012-12-25T18:25:43.613 回答