1
我是非常新的Windows移動開發和MSFT同步框架作爲一個頭。我有一個簡單的應用程序,讀取條形碼,從數據庫中檢索條目,並讓用戶輸入新的讀數。這一切都很好。然而,當我嘗試同步,我得到以下異常:微軟同步框架新手 - 參數異常未處理
System.ArgumentException was unhandled
Message="ArgumentException"
StackTrace:
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.Synchronization.Data.ServerSyncProviderProxy.ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
at Microsoft.Synchronization.SyncAgent.UploadChanges(SyncGroupMetadata groupMetadata)
at Microsoft.Synchronization.SyncAgent.Synchronize()
at ElectricBarcodeApp.Form1.buttonSync_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at ElectricBarcodeApp.Program.Main()
這裏是我的代碼:
// Synchronize the databases
Microsoft.Synchronization.Data.SyncStatistics stats = syncAgent.Synchronize();
我一直是:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.IO;
using System.Reflection;
namespace ElectricBarcodeApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
using (SqlCeConnection conn = new SqlCeConnection(
("Data Source=" + (Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "ElectricReading.sdf") + ";Max Database Size=2047"))))
{
// Connect to the local database
conn.Open();
using (SqlCeCommand cmd = conn.CreateCommand())
{
SqlCeParameter param = new SqlCeParameter();
param.ParameterName = "@Barcode";
param.DbType = DbType.String;
param.Value = textBarcode.Text.Trim();
// SELECT rows
cmd.CommandText = "SELECT Location, Reading FROM Main2 WHERE Barcode LIKE @Barcode";
cmd.Parameters.Add(param);
DataTable data = new DataTable();
using (SqlCeDataReader reader = cmd.ExecuteReader())
{
data.Load(reader);
this.dataGrid1.DataSource = data;
}
}
}
}
private void buttonEnter_Click(object sender, EventArgs e)
{
using (SqlCeConnection conn = new SqlCeConnection(
("Data Source=" + (Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "ElectricReading.sdf") + ";Max Database Size=2047"))))
{
// Connect to the local database
conn.Open();
using (SqlCeCommand cmd = conn.CreateCommand())
{
// INSERT NEW READING
cmd.CommandText = "UPDATE Main2 SET Reading = '" + textNewReading.Text.Trim() + "' WHERE Barcode LIKE '" + textBarcode.Text.Trim() + "'";
int m = cmd.ExecuteNonQuery();
cmd.ExecuteNonQuery();
if (m > 0)
{
MessageBox.Show("New Reading Successfully Entered:" + textNewReading.Text.Trim(), "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
}
}
}
}
private void buttonSync_Click(object sender, EventArgs e)
{
// The WCF Service
ElectricReadingCacheWebRef.ElectricReadingCacheSyncService webSvcProxy = new
ElectricBarcodeApp.ElectricReadingCacheWebRef.ElectricReadingCacheSyncService();
// The Remote Server Provider Proxy
Microsoft.Synchronization.Data.ServerSyncProviderProxy serverProvider = new
Microsoft.Synchronization.Data.ServerSyncProviderProxy(webSvcProxy);
// The Sync Agent
ElectricReadingCacheSyncAgent syncAgent = new ElectricReadingCacheSyncAgent();
syncAgent.RemoteProvider = serverProvider;
//Main2 is the table to be synchronized
syncAgent.Main2.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional;
// Synchronize the databases
Microsoft.Synchronization.Data.SyncStatistics stats = syncAgent.Synchronize();
// Show synchronization statistics
MessageBox.Show("Changes Downloaded: " + stats.TotalChangesDownloaded.ToString() +
"\r\n" + "Changes Uploaded: " + stats.TotalChangesUploaded.ToString());
}
}
}
唯一的例外是在這條線拋出無法找到解決方案和任何幫助非常感謝!
編輯:我想這可能是因爲我沒有:
using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
但補充說,並沒有改變例外。
如果您沒有'using'語句,代碼將不會編譯。 – ChrisF 2012-03-23 20:12:32
您還應該發佈ElectricReadingCacheSyncAgent代碼,因爲它是引發excpetion的地方。 – 2012-03-23 20:56:23
這似乎是與WCF有關的錯誤,您是如何生成客戶端代理的? – JuneT 2012-03-24 09:26:05