2014-01-14 3 views
0

Я пытаюсь синхронизировать две базы данных SQL Server, следуя примеру Microsoft Synchronizing SQL Server and SQL Express, и основная синхронизация работает на меня. Теперь я попытался создать конфликт, изменив ту же строку на обоих БД на разные значения, но когда я запустил процесс синхронизации, приложение ApplyChangeFailed не запускается.ApplyChangeFailed не запускается при конфликте

Я прочитал этот вопрос Microsoft Sync Framework Conflict Event does not fire, но я не понимаю, почему при синхронизации клиента < -> Конфигурация сервера игнорирует конфликты.

Вот мой код, только для справки, у меня есть удаленный SQL 2008 R2 Server, как сервер и локальный SQL 2012 Express, как клиент:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Data.SqlClient; 
using Microsoft.Synchronization; 
using Microsoft.Synchronization.Data; 
using Microsoft.Synchronization.Data.SqlServer; 
using Microsoft.Synchronization.Data.SqlServerCe; 

namespace ExecuteExpressSync 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      SqlConnection clientConn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial Catalog=SyncExpressDB; Trusted_Connection=Yes"); 
      SqlConnection serverConn = new SqlConnection("Data Source=X.Y.Z.W; Initial Catalog=SyncDB; uid=sa;password=******;Integrated Security=False"); 

      // create the sync orhcestrator 
      SyncOrchestrator syncOrchestrator = new SyncOrchestrator(); 

      // set local provider of orchestrator to a sync provider associated with the 
      // ProductsScope in the SyncExpressDB express client database 
      syncOrchestrator.LocalProvider = new SqlSyncProvider("ProductsScope", clientConn); 

      // set the remote provider of orchestrator to a server sync provider associated with 
      // the ProductsScope in the SyncDB server database 
      syncOrchestrator.RemoteProvider = new SqlSyncProvider("ProductsScope", serverConn); 

      // set the direction of sync session to Upload and Download 
      syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload; 

      // subscribe for errors that occur when applying changes to the client 
      ((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed); 

      // execute the synchronization process 
      SyncOperationStatistics syncStats = syncOrchestrator.Synchronize(); 

      // print statistics 
      Console.WriteLine("Start Time: " + syncStats.SyncStartTime); 
      Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal); 
      Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal); 
      Console.WriteLine("Complete Time: " + syncStats.SyncEndTime); 
      Console.WriteLine(String.Empty); 
     } 

     static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e) 
     { 
      // display conflict type 
      Console.WriteLine(e.Conflict.Type); 

      // display error message 
      Console.WriteLine(e.Error); 
     } 
    } 
} 
+0

Подпишитесь, чтобы применить changefailed событие на удаленном провайдере, и вы увидите его пожар – JuneT

+0

Спасибо! Это сделало трюк – Eyal

ответ

0

Как отмечает @JuneT эта линия отсутствует:

// subscribe for errors that occur when applying changes to the client 
((SqlSyncProvider)syncOrchestrator.RemoteProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed); 
Смежные вопросы