1

新しい c# プロジェクトを作成し、このチュートリアルの手順に従って 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

次に、次のコードを追加しました。

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 データベース) は同期が行われる前と同じであり、変更は保存されていません。

今、何が欠けているのかわからないのですか?シンプルなものに違いない!どんなアドバイスでも大歓迎です。

ありがとうございました

4

1 に答える 1

2

これで解決しました。

問題は、database.sdf が常にデータ出力ディレクトリにコピーされ、作業中のデータベースを上書きすることです (マージをテストするために手動で変更を加えます!)。

これは、Visual Studio で sdf ファイルをクリックし、プロパティで [出力ディレクトリにコピー] の値を [コピーしない] に変更することで変更できます。次に、データ ディレクトリの外部で接続文字列を管理します。デフォルトは Copy If newer で、これが問題の原因でした!

于 2009-11-20T13:02:17.930 に答える