我创建了一个新的 c# 项目,并按照本教程中的步骤创建了 LocalDate 缓存:
我接下来添加了以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestLocalSync
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the table. You can move, or remove it, as needed.
this.databaseTableAdapter.Fill(this.testDataSet.myTable);
}
private void Sync_Click(object sender, EventArgs e)
{
dataGridView1.EndEdit();
// 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.testTable.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional;
Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();
MessageBox.Show("Changes downloaded: " +
syncStats.TotalChangesDownloaded.ToString() +
Environment.NewLine +
"Changes uploaded: " + syncStats.TotalChangesUploaded.ToString());
// TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
databaseTableAdapter.Fill(testDataSet.myTable);
testDataSet.Merge(databaseTableAdapter.GetData());
databaseTableAdapter.Update(testDataSet);
}
private void Refresh_Click(object sender, EventArgs e)
{
databaseTableAdapter.Fill(testDataSet.myTable);
}
}
}
我对服务器上的数据库进行了一些更改并执行同步,它似乎更新了客户端数据网格。当我重新加载应用程序时,客户端(sdf 数据库)与同步发生之前相同,并且未存储任何更改。
现在我不确定我错过了什么?一定是简单的事情!任何建议都会被极大地接受。
谢谢
现在这个问题已经解决了。
问题是,database.sdf 总是被复制到数据输出目录,并且会覆盖我正在处理的数据库(手动进行更改以测试合并!)。
可以通过单击 Visual Studio 中的 sdf 文件来更改此设置,并在属性中将“复制到输出目录”的值更改为“不复制”。然后在数据目录之外管理连接字符串。默认值是 Copy If newer,这导致了问题!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)