我想與SQL Azure數據庫同步Sql Server數據庫(請耐心等待,因爲我不完全瞭解同步框架)。這些是要求:上傳和下載錯誤同步Sql服務器和Sql Azure - 同步框架
- 第一:從SQL天青同步1和表到SQL Server
- 第二:同步其它13個表(包括我在第一步驟中提到的表)從SQL Server天青。 我創建了一個控制檯應用程序,這是代碼:
1.I創建一個範圍與13個表:
DbSyncScopeDescription myScope = new DbSyncScopeDescription("alltablesyncgroup");
DbSyncTableDescription table = qlSyncDescriptionBuilder.GetDescriptionForTable("tablename", sqlServerConn);
myScope.Tables.Add(table); //repeated 13 times.
2.I提供了數據基礎:
SqlSyncScopeProvisioning sqlAzureProv = new SqlSyncScopeProvisioning(sqlAzureConn,myScope);
if (!sqlAzureProv.ScopeExists("alltablesyncgroup"))
{
sqlAzureProv.Apply();
}
SqlSyncScopeProvisioning sqlServerProv = new SqlSyncScopeProvisioning(sqlServerConn, myScope);
if (!sqlServerProv.ScopeExists("alltablesyncgroup"))
{
sqlServerProv.Apply();
}
3.I創建SyncOrchestrator與SyncDirectionOrder.Download同步的firts表:
SqlConnection sqlServerConn = new SqlConnection(sqllocalConnectionString);
SqlConnection sqlAzureConn = new SqlConnection(sqlazureConnectionString);
SyncOrchestrator orch = new SyncOrchestrator
{
RemoteProvider = new SqlSyncProvider(scopeName, sqlAzureConn),
LocalProvider = new SqlSyncProvider(scopeName, sqlServerConn),
Direction = SyncDirectionOrder.Download
};
orch.Synchronize();
4.Later,我用的是同樣的功能只改變方向SyncDirectionOrder.Upload同步剩餘的13臺
SqlConnection sqlServerConn = new SqlConnection(sqllocalConnectionString);
SqlConnection sqlAzureConn = new SqlConnection(sqlazureConnectionString);
SyncOrchestrator orch = new SyncOrchestrator
{
RemoteProvider = new SqlSyncProvider(scopeName, sqlAzureConn),
LocalProvider = new SqlSyncProvider(scopeName, sqlServerConn),
Direction = SyncDirectionOrder.Upload
};
orch.Synchronize();
現在,這裏是東西,明明我做錯了「因爲當我下載,syncStats顯示已經應用了很多改變,但是我看不到它反映在任何數據庫上,當我嘗試執行上傳同步時,它似乎進入循環,因爲上傳過程沒有停止。
謝謝!