Local Data Cache Sync does not save client changes to sdf file

放肆的年华 提交于 2020-01-21 19:24:05

问题


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

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.

Thank you


回答1:


This is solved now.

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!).

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!



来源:https://stackoverflow.com/questions/1769491/local-data-cache-sync-does-not-save-client-changes-to-sdf-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!