2012-07-10 52 views
0

我試圖在我的移動設備和數據庫服務器之間創建同步。我正在關注this tutorial,它在sych()函數中獲得ArgumentNullException Value can not be null. Parameter name: ServerSyncProvider針對移動設備的ADO.NET解決方案的同步服務 - ArgumentNullException

代碼

private void Sync() 
     { 
      Cursor.Current = Cursors.WaitCursor; 
      WebReference.NorthwindCacheSyncService svcProxy = new WebReference.NorthwindCacheSyncService(); 
      Microsoft.Synchronization.Data.ServerSyncProviderProxy syncProxy = 
       new Microsoft.Synchronization.Data.ServerSyncProviderProxy(svcProxy); 
      // Call SyncAgent.Synchronize() to initiate the synchronization process. 
      // Synchronization only updates the local database, not your project's data source. 
      NorthwindCacheSyncAgent syncAgent = new NorthwindCacheSyncAgent(); 
      Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize(); 

      // TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method). 
      // Show synchronization statistics 
      MessageBox.Show("Changes downloaded: " + syncStats.TotalChangesDownloaded.ToString() 
       + "\r\nChanges Uploaded: " + syncStats.TotalChangesUploaded.ToString()); 

      Cursor.Current = Cursors.Default; 

     } 

回答

0

由於錯誤說:「值不能爲空參數名:ServerSyncProvider」

意味着它沒有被初始化

你已經錯過了一行代碼inbetween

NorthwindCacheSyncAgent syncAgent = new NorthwindCacheSyncAgent();

syncAgent.RemoteProvider = syncProxy 
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();