本地数据缓存同步不会将客户端更改保存到sdf文件 [英] Local Data Cache Sync does not save client changes to sdf file

查看:187
本文介绍了本地数据缓存同步不会将客户端更改保存到sdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的c#项目,接下来本教程中的步骤创建一个LocalDataCache:

I created a new c# project and follwed the steps from this tutorial to create a LocalDataCache:

http://www.codeproject.com/KB/database/AdoSyncServicesArticalPKg.aspx?fid=1526739&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2794305&fr=1# xx0xx

我接下来添加了以下代码:

I next added the following code:

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);
        }
    }
}

我对数据库,并执行同步,并显示更新客户端datagrid。当我重新加载应用程序时,客户端(sdf数据库)在发生同步之前是相同的,没有更改已经被保存。

I make some changes to the database on the server and perform the sync and it appears update the client datagrid. When I re-load the application, the client (sdf database) is the same before the sync took place and no changes have been stored.

现在我不知道我失踪了什么?一定要简单一些!任何建议都是非常接受的。

Now I am not sure what I am missing? Must be something simple! Any advice is greatfully accepted.

谢谢

推荐答案

现在解决了

问题是数据库.sdf总是复制到数据输出目录,并覆盖我正在处理的数据库(手动进行更改以测试合并!) 。

The problem is that the database.sdf is always copied to the data output directory and would overwrite the database I was working on (manually making changes to test the merge!).

可以通过在visual studio中单击sdf文件并在属性中将复制到输出目录的值更改为不要复制来更改。然后管理数据目录外的连接字符串。默认为Copy If newer,导致问题!

This can be changed by clicking on the sdf file in visual studio and in properties change the value for "Copy to Output Directory" to "Do Not Copy". Then manage the connection string outside of the data directory. The default is Copy If newer which caused the problems!

这篇关于本地数据缓存同步不会将客户端更改保存到sdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆