C# C语言中的数据同步#
我已经在页面加载事件中添加了这段代码,并且本地数据库中的数据正在与服务器数据库同步,但是我没有返回服务器数据库中的值C# C语言中的数据同步#,c#,synchronization,sync,microsoft-sync-framework,C#,Synchronization,Sync,Microsoft Sync Framework,我已经在页面加载事件中添加了这段代码,并且本地数据库中的数据正在与服务器数据库同步,但是我没有返回服务器数据库中的值 void HomeLoad(object sender, EventArgs e) { this.Validate(); clientBindingSource.EndEdit(); tableAdapterManager1.UpdateAll(this.DataSet); //
void HomeLoad(object sender, EventArgs e)
{
this.Validate();
clientBindingSource.EndEdit();
tableAdapterManager1.UpdateAll(this.DataSet);
// Call SyncAgent.Synchronize() to initiate the synchronization process.
// Synchronization only updates the local database, not your project’s data source.
LocalDataCache1SyncAgent syncAgent = new LocalDataCache1SyncAgent();
syncAgent.tbl_Miscellaneous.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional;
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
//TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
miscellaneousTableAdapter1.Update(DataSet.Miscellaneous);
miscellaneousTableAdapter1.Fill(DataSet.Miscellaneous);
DataSet.Miscellaneous.Merge(this.miscellaneousTableAdapter1.GetData());
}
我还添加了论坛中提到的LocalDataCache1.sync中的代码,并将database.sdf更改为“不复制”
来自服务器的数据正在填充Tableadapter,但未更新本地数据库
void HomeLoad(object sender, EventArgs e)
{
this.Validate();
clientBindingSource.EndEdit();
tableAdapterManager1.UpdateAll(this.DataSet);
// Call SyncAgent.Synchronize() to initiate the synchronization process.
// Synchronization only updates the local database, not your project’s data source.
LocalDataCache1SyncAgent syncAgent = new LocalDataCache1SyncAgent();
syncAgent.tbl_Miscellaneous.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional;
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
//TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
miscellaneousTableAdapter1.Update(DataSet.Miscellaneous);
miscellaneousTableAdapter1.Fill(DataSet.Miscellaneous);
DataSet.Miscellaneous.Merge(this.miscellaneousTableAdapter1.GetData());
}
它不会自动更新到本地数据库。
您需要使用已复制服务器数据库的数据表和数据集手动添加此数据。只是为了澄清,本地数据库中的更改会反映在服务器中,但服务器中的更改不会同步回您的客户端?是的,JuneT,我得到的更改与您提到的相同。请尝试订阅ApplyChangeFailed事件,查看从服务器应用更改时是否有错误,或订阅服务器端的ChangesSelected事件,并确认更改是否已被选中。您好,添加所有代码后,我收到如下错误:值不能为null。此代码中存在错误“Microsoft.Synchronization.Data.SyncStatistics syncStats=syncAgent.Synchronize();”参数名称:ServerSyncProvider“任何人都知道这个错误是什么。你能发布实际的堆栈跟踪吗?如果你要手动添加记录,为什么需要同步框架呢?”?你读过这个问题吗?