SqlCeReplication.BeginSynchronizeとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > SqlCeReplication.BeginSynchronizeの意味・解説 

SqlCeReplication.BeginSynchronize メソッド (AsyncCallback, OnStartTableUpload, OnStartTableDownload, OnSynchronization, Object)

非同期データの同期操作を開始します。同期が終了すると、AsyncCallBack デリゲートが呼び出されます。同期中に、同期ステータス レポートが SyncStatusReport デリゲートに送信されます。

名前空間: System.Data.SqlServerCe
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文構文

Public Function BeginSynchronize ( _
    onSyncCompletion As AsyncCallback, _
    onStartTableUpload As OnStartTableUpload, _
    onStartTableDownload As OnStartTableDownload, _
    onSynchronization As OnSynchronization, _
    state As Object _
) As IAsyncResult
Dim instance As SqlCeReplication
Dim onSyncCompletion As AsyncCallback
Dim onStartTableUpload As OnStartTableUpload
Dim onStartTableDownload As OnStartTableDownload
Dim onSynchronization As OnSynchronization
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginSynchronize(onSyncCompletion, onStartTableUpload, onStartTableDownload,
 onSynchronization, state)
public IAsyncResult BeginSynchronize (
    AsyncCallback onSyncCompletion,
    OnStartTableUpload onStartTableUpload,
    OnStartTableDownload onStartTableDownload,
    OnSynchronization onSynchronization,
    Object state
)
public:
IAsyncResult^ BeginSynchronize (
    AsyncCallback^ onSyncCompletion, 
    OnStartTableUpload^ onStartTableUpload, 
    OnStartTableDownload^ onStartTableDownload, 
    OnSynchronization^ onSynchronization, 
    Object^ state
)
public IAsyncResult BeginSynchronize (
    AsyncCallback onSyncCompletion, 
    OnStartTableUpload onStartTableUpload, 
    OnStartTableDownload onStartTableDownload, 
    OnSynchronization onSynchronization, 
    Object state
)
public function BeginSynchronize (
    onSyncCompletion : AsyncCallback, 
    onStartTableUpload : OnStartTableUpload, 
    onStartTableDownload : OnStartTableDownload, 
    onSynchronization : OnSynchronization, 
    state : Object
) : IAsyncResult

パラメータ

onSyncCompletion

呼び出し元によって実装され、同期操作の最後に呼び出される AsyncCallBack デリゲート。

onStartTableUpload

サーバーへのテーブル変更のアップロードが開始されるときに起動されるイベントに対するユーザー定義のデリゲート。

onStartTableDownload

サーバーからテーブル変更のダウンロードが開始されるときに起動されるイベントに対するユーザー定義のデリゲート。

onSynchronization

競合回避モジュールの動作中に報告された実行中の同期イベントを処理するユーザー定義のデリゲート。

state

IAsyncResult.AsyncState プロパティによって返されるユーザー定義のオブジェクト。

戻り値
この関数を呼び出すことによって開始される非同期操作の IAsyncResult インターフェイス。このインターフェイスを使用して、完了テストを実行したり、同期が終了するまで待機したりできます。

解説解説
使用例使用例

非同期データを同期化させるために SQL Server Mobile のレプリケーションをセットアップする方法を次の例に示します。

' Imports System;
' Imports System.Data;
' Imports System.IO;
' Imports System.Data.SqlServerCe;
' Imports System.Windows.Forms;

'/ <summary>
'/ Demonstrates the usage of asynchronous database synchronization
'/ </summary>
Public Class MyForm
    Inherits Form

    Private myUserInterfaceUpdateEvent As EventHandler
    Private tableName As String
    Private percentage As Integer
    Private eventStatus As SyncStatus
    Private repl As SqlCeReplication

    Friend Enum SyncStatus
        PercentComplete
        BeginUpload
        BeginDownload
        SyncComplete
    End Enum 'SyncStatus

    Public Sub New()
        ' InitializeComponent();
        Me.myUserInterfaceUpdateEvent = New
 EventHandler(AddressOf UserInterfaceUpdateEvent)

    End Sub 'New

    Private Sub UserInterfaceUpdateEvent(ByVal
 sender As Object, ByVal
 e As System.EventArgs)
        Select Case Me.eventStatus
            Case SyncStatus.BeginUpload
                'this.labelStatusValue.Text = "Began uploading
 table : " & tableName;

            Case SyncStatus.PercentComplete
                'this.labelStatusValue.Text = "Sync with SQL Server
 is " & percentage.ToString() & "% complete.";

            Case SyncStatus.BeginDownload
                'this.labelStatusValue.Text = "Began downloading
 table : " & tableName;

            Case SyncStatus.SyncComplete
                'this.labelStatusValue.Text = "Synchronization
 has completed successfully";
                'this.labelLastSyncValue.Text = GetLastSuccessfulSyncTime().ToString();
        End Select
    End Sub 'UserInterfaceUpdateEvent

    Public Sub SyncCompletedCallback(ByVal
 ar As IAsyncResult)
        Try
            Dim repl As SqlCeReplication =
 CType(ar.AsyncState, SqlCeReplication)

            repl.EndSynchronize(ar)
            repl.SaveProperties()

            Me.eventStatus = SyncStatus.SyncComplete
        Catch e As SqlCeException
            MessageBox.Show(e.Message)
        Finally
            ' NOTE: If you'd like to set Control properties from within
 this 
            ' method, you need to use Control.Invoke method in order
 to marshal
            ' the call to the UI thread; otherwise you might deadlock
 your 
            ' application; See Control.Invoke documentation for more
 information
            '
            Me.Invoke(Me.myUserInterfaceUpdateEvent)
        End Try

    End Sub 'SyncCompletedCallback

    Public Sub OnStartTableUploadCallback(ByVal
 ar As IAsyncResult, ByVal tableName As
 String)
        Me.tableName = tableName
        Me.eventStatus = SyncStatus.BeginUpload

        ' NOTE: If you'd like to set Control properties from within
 this 
        ' method, you need to use Control.Invoke method in order to
 marshal
        ' the call to the UI thread; otherwise you might deadlock your
 
        ' application; See Control.Invoke documentation for more information
        '
        Me.Invoke(Me.myUserInterfaceUpdateEvent)

    End Sub 'OnStartTableUploadCallback

    Public Sub OnSynchronizationCallback(ByVal
 ar As IAsyncResult, ByVal percentComplete
 As Integer)
        Me.percentage = percentComplete
        Me.eventStatus = SyncStatus.PercentComplete

        ' NOTE: If you'd like to set Control properties from within
 this 
        ' method, you need to use Control.Invoke method in order to
 marshal
        ' the call to the UI thread; otherwise you might deadlock your
 
        ' application; See Control.Invoke documentation for more information
        '
        Me.Invoke(Me.myUserInterfaceUpdateEvent)

    End Sub 'OnSynchronizationCallback

    Public Sub OnStartTableDownloadCallback(ByVal
 ar As IAsyncResult, ByVal tableName As
 String)
        Me.tableName = tableName
        Me.eventStatus = SyncStatus.BeginDownload

        ' NOTE: If you'd like to set Control properties from within
 this 
        ' method, you need to use Control.Invoke method in order to
 marshal
        ' the call to the UI thread; otherwise you might deadlock your
 
        ' application; See Control.Invoke documentation for more information
        '
        Me.Invoke(Me.myUserInterfaceUpdateEvent)

    End Sub 'OnStartTableDownloadCallback

    Private Sub ButtonSynchronize_Click(ByVal
 sender As Object, ByVal
 e As System.EventArgs)
        Try
            Me.repl = New SqlCeReplication()
            repl.SubscriberConnectionString = "Data Source=Test.sdf"

            If False = File.Exists("Test.sdf")
 Then
                repl.AddSubscription(AddOption.CreateDatabase)
                repl.PublisherSecurityMode = SecurityType.DBAuthentication
                repl.Publisher = "MyPublisher"
                repl.PublisherLogin = "PublisherLogin"
                repl.PublisherPassword = "<Password>"
                repl.PublisherDatabase = "AdventureWorksDW"
                repl.Publication = "AdventureWorksDW"
                repl.InternetUrl = "http://www.adventure-works.com/sqlmobile/sqlcesa30.dll"
                repl.InternetLogin = "InternetLogin"
                repl.InternetPassword = "<Password>"
                repl.Subscriber = "MySubscriber"
            Else
                repl.LoadProperties()
            End If

            Dim ar As IAsyncResult = repl.BeginSynchronize(
 _
                New AsyncCallback(AddressOf
 Me.SyncCompletedCallback), _
                New OnStartTableUpload(AddressOf
 Me.OnStartTableUploadCallback), _
                New OnStartTableDownload(AddressOf
 Me.OnStartTableDownloadCallback), _
                New OnSynchronization(AddressOf
 Me.OnSynchronizationCallback), repl)

        Catch ex As SqlCeException
            MessageBox.Show(ex.Message)
        End Try

    End Sub 'ButtonSynchronize_Click

    Public Function GetLastSuccessfulSyncTime()
 As DateTime
        Dim utcDateTime As DateTime
        Dim localDateTime As DateTime

        Dim conn As SqlCeConnection = Nothing
        Dim cmd As SqlCeCommand = Nothing

        Try
            conn = New SqlCeConnection("Data
 Source = Test.sdf")
            conn.Open()

            cmd = conn.CreateCommand()
            cmd.CommandText = "SELECT LastSuccessfulSync FROM
 __sysMergeSubscriptions " & _
                "WHERE Publication=@publication"

            cmd.Parameters.Add("@publication", SqlDbType.NVarChar,
 4000)
            cmd.Parameters("@publication").Value =
 "AdventureWorksDW"

            utcDateTime = CType(cmd.ExecuteScalar(), DateTime)
            localDateTime = utcDateTime.ToLocalTime()

            Return localDateTime
        Finally
            conn.Close()
        End Try

    End Function 'GetLastSuccessfulSyncTime
End Class 'MyForm
// using System;
// using System.Data;
// using System.IO;
// using System.Data.SqlServerCe;
// using System.Windows.Forms;

/// <summary>
/// Demonstrates the usage of asynchronous database synchronization
/// </summary>
public class MyForm : Form
{
    private string tableName;
    private int percentage;
    private SyncStatus eventStatus;
    private SqlCeReplication repl;
    private EventHandler myUserInterfaceUpdateEvent;

    internal enum SyncStatus
    {
        PercentComplete,
        BeginUpload,
        BeginDownload,
        SyncComplete
    }

    public MyForm()
    {
        // InitializeComponent();
        this.myUserInterfaceUpdateEvent = new
 EventHandler(MyUserInterfaceUpdateEvent);
    }

    private void MyUserInterfaceUpdateEvent(object
 sender, System.EventArgs e)
    {
        switch (this.eventStatus)
        {
            case SyncStatus.BeginUpload:
                //this.labelStatusValue.Text = "Began uploading
 table : " + tableName;
                break;

            case SyncStatus.PercentComplete:
                //this.labelStatusValue.Text = "Sync with SQL Server
 is " + percentage.ToString() + "% complete.";
                break;

            case SyncStatus.BeginDownload:
                //this.labelStatusValue.Text = "Began downloading
 table : " + tableName;
                break;

            case SyncStatus.SyncComplete:
                //this.labelStatusValue.Text = "Synchronization
 has completed successfully";
                //this.labelLastSyncValue.Text = GetLastSuccessfulSyncTime().ToString();
                break;
        }
    }

    public void SyncCompletedCallback(IAsyncResult
 ar)
    {
        try
        {
            SqlCeReplication repl = (SqlCeReplication)ar.AsyncState;

            repl.EndSynchronize(ar);
            repl.SaveProperties();

            this.eventStatus = SyncStatus.SyncComplete;
        }
        catch (SqlCeException e)
        {
            MessageBox.Show(e.Message);
        }
        finally
        {
            // NOTE: If you'd like to set Control properties from within
 this 
            // method, you need to use Control.Invoke method in order
 to marshal
            // the call to the UI thread; otherwise you might deadlock
 your 
            // application; See Control.Invoke documentation for more
 information
            //
            this.Invoke(this.myUserInterfaceUpdateEvent);
        }
    }

    public void OnStartTableUploadCallback(IAsyncResult
 ar, string tableName)
    {
        this.tableName = tableName;
        this.eventStatus = SyncStatus.BeginUpload;

        // NOTE: If you'd like to set Control properties from within
 this 
        // method, you need to use Control.Invoke method in order to
 marshal
        // the call to the UI thread; otherwise you might deadlock your
 
        // application; See Control.Invoke documentation for more information
        //
        this.Invoke(this.myUserInterfaceUpdateEvent);
    }

    public void OnSynchronizationCallback(IAsyncResult
 ar, int percentComplete)
    {
        this.percentage = percentComplete;
        this.eventStatus = SyncStatus.PercentComplete;

        // NOTE: If you'd like to set Control properties from within
 this 
        // method, you need to use Control.Invoke method in order to
 marshal
        // the call to the UI thread; otherwise you might deadlock your
 
        // application; See Control.Invoke documentation for more information
        //
        this.Invoke(this.myUserInterfaceUpdateEvent);
    }

    public void OnStartTableDownloadCallback(IAsyncResult
 ar, string tableName)
    {
        this.tableName = tableName;
        this.eventStatus = SyncStatus.BeginDownload;

        // NOTE: If you'd like to set Control properties from within
 this 
        // method, you need to use Control.Invoke method in order to
 marshal
        // the call to the UI thread; otherwise you might deadlock your
 
        // application; See Control.Invoke documentation for more information
        //
        this.Invoke(this.myUserInterfaceUpdateEvent);
    }

    private void ButtonSynchronize_Click(object
 sender, System.EventArgs e)
    {
        try
        {
            this.repl = new SqlCeReplication();
            repl.SubscriberConnectionString = "Data Source=Test.sdf";

            if (false == File.Exists("Test.sdf"))
            {
                repl.AddSubscription(AddOption.CreateDatabase);
                repl.PublisherSecurityMode = SecurityType.DBAuthentication;
                repl.Publisher = "MyPublisher";
                repl.PublisherLogin = "PublisherLogin";
                repl.PublisherPassword = "<Password>";
                repl.PublisherDatabase = "AdventureWorksDW";
                repl.Publication = "AdventureWorksDW";
                repl.InternetUrl = "http://www.adventure-works.com/sqlmobile/sqlcesa30.dll";
                repl.InternetLogin = "MyInternetLogin";
                repl.InternetPassword = "<Password";
                repl.Subscriber = "MySubscriber";
            }
            else
            {
                repl.LoadProperties();
            }

            IAsyncResult ar = repl.BeginSynchronize(
                new AsyncCallback(this.SyncCompletedCallback)
,
                new OnStartTableUpload(this.OnStartTableUploadCallback)
,
                new OnStartTableDownload(this.OnStartTableDownloadCallback)
,
                new OnSynchronization(this.OnSynchronizationCallback),
 
                repl);
        }
        catch (SqlCeException ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    public DateTime GetLastSuccessfulSyncTime()
    {
        DateTime utcDateTime;
        DateTime localDateTime;
        SqlCeConnection conn = null;
        SqlCeCommand cmd = null;

        try
        {
            conn = new SqlCeConnection("Data Source = Test.sdf");
            conn.Open();

            cmd = conn.CreateCommand();
            cmd.CommandText = "SELECT LastSuccessfulSync FROM __sysMergeSubscriptions
 " +
                "WHERE Publication=@publication";

            cmd.Parameters.Add("@publication", SqlDbType.NVarChar, 4000);
            cmd.Parameters["@publication"].Value = "AdventureWorksDW";

            utcDateTime = (DateTime)cmd.ExecuteScalar();
            localDateTime = utcDateTime.ToLocalTime();

            return localDateTime;
        }
        finally
        {
            conn.Close();
        }
    }
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlCeReplication クラス
SqlCeReplication メンバ
System.Data.SqlServerCe 名前空間

SqlCeReplication.BeginSynchronize メソッド

非同期データの同期化を開始します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
SqlCeReplication.BeginSynchronize (AsyncCallback, Object) 非同期データの同期操作を開始します。同期が終了すると、AsyncCallBack デリゲートが呼び出されます。同期中には、ステータス レポートが実行されません。

.NET Compact Framework によってサポートされています。

SqlCeReplication.BeginSynchronize (AsyncCallback, OnStartTableUpload, OnStartTableDownload, OnSynchronization, Object) 非同期データの同期操作を開始します。同期が終了すると、AsyncCallBack デリゲートが呼び出されます。同期中に、同期ステータス レポートが SyncStatusReport デリゲートに送信されます。

.NET Compact Framework によってサポートされています。

参照参照

関連項目

SqlCeReplication クラス
SqlCeReplication メンバ
System.Data.SqlServerCe 名前空間

SqlCeReplication.BeginSynchronize メソッド (AsyncCallback, Object)

非同期データの同期操作を開始します。同期が終了すると、AsyncCallBack デリゲートが呼び出されます。同期中には、ステータス レポートが実行されません。

名前空間: System.Data.SqlServerCe
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)
構文構文

Public Function BeginSynchronize ( _
    onSyncCompletion As AsyncCallback, _
    state As Object _
) As IAsyncResult
Dim instance As SqlCeReplication
Dim onSyncCompletion As AsyncCallback
Dim state As Object
Dim returnValue As IAsyncResult

returnValue = instance.BeginSynchronize(onSyncCompletion, state)
public IAsyncResult BeginSynchronize (
    AsyncCallback onSyncCompletion,
    Object state
)
public:
IAsyncResult^ BeginSynchronize (
    AsyncCallback^ onSyncCompletion, 
    Object^ state
)
public IAsyncResult BeginSynchronize (
    AsyncCallback onSyncCompletion, 
    Object state
)
public function BeginSynchronize (
    onSyncCompletion : AsyncCallback, 
    state : Object
) : IAsyncResult

パラメータ

onSyncCompletion

呼び出し元によって実装され、同期の最後に呼び出される IAsyncResult デリゲート。

state

IAsyncResult.AsyncState プロパティによって返されるユーザー定義のオブジェクト。

戻り値
この関数を呼び出すことによって開始される非同期操作の IAsyncResult インターフェイス。このインターフェイスを使用して、完了テストを実行したり、同期が終了するまで待機したりできます。

解説解説
使用例使用例

非同期データを同期化させるために SQL Server Mobile のレプリケーションをセットアップする方法を次の例に示します。

Public Sub SyncCompletedCallback(ByVal
 ar As IAsyncResult)
    Try
        Dim repl As SqlCeReplication = CType(ar.AsyncState,
 SqlCeReplication)

        ' Complete the asynchronous sync and test for errors
        '
        repl.EndSynchronize(ar)
    Catch
        ' Handle errors here
        '
    End Try

End Sub 'SyncCompletedCallback

Public Sub Test()
    Dim repl As SqlCeReplication = Nothing

    Try
        ' Set the Replication object
        '
        repl = New SqlCeReplication( _
            "http://www.adventure-works.com/sqlmobile/sqlcesa30.dll",
 _
            "MyInternetLogin", _
            "<password>", _
            "MyPublisher", _
            "MyPublisherDatabase", _
            "MyPublisherLogin", _
            "<password>", _
            "MyPublication", _
            "MySubscriber", _
            "Data Source=MyDatabase.sdf")

        ' Begin asynchronous sync; This call returns immediately 
        '
        Dim ar As IAsyncResult = repl.BeginSynchronize(
 _
            New AsyncCallback(AddressOf SyncCompletedCallback),
 _
            repl)

        Thread.Sleep(3000)

        ' Cancel the sync if it didn't complete in 3 seconds; normally
,
        ' this is hooked up to a button's Click event
        '
        repl.CancelSynchronize()
    Catch
        ' Handle errors here
    Finally
        ' Dispose the repl object
        '
        repl.Dispose()
    End Try

End Sub 'Test
public void SyncCompletedCallback(IAsyncResult
 ar)
{
    try
    {
        SqlCeReplication repl = (SqlCeReplication)ar.AsyncState;

        // Complete the asynchronous sync and test for errors
        //
        repl.EndSynchronize(ar);
    }
    catch (SqlCeException)
    {
        // Handle errors here
        //
    }
}

public void Test()
{
    SqlCeReplication repl = null;

    try
    {
        // Set the Replication object
        //
        repl = new SqlCeReplication(
            "http://www.adventure-works.com/sqlmobile/sqlcesa30.dll"
,
            "MyInternetLogin",
            "<password>",
            "MyPublisher",
            "MyPublisherDatabase",
            "MyPublisherLogin",
            "<password>",
            "MyPublication",
            "MySubscriber",
            "Data Source=MyDatabase.sdf");

        // Begin asynchronous sync; This call returns immediately 
        //
        IAsyncResult ar = repl.BeginSynchronize(
            new AsyncCallback(SyncCompletedCallback),
            repl);

        Thread.Sleep(3000);

        // Cancel the sync if it didn't complete in 3 seconds; normally
,
        // this is hooked up to a button's Click event
        //
        repl.CancelSynchronize();
    }
    catch (SqlCeException)
    {
        // Handle errors here
    }
    finally
    {
        // Dispose the repl object
        //
        repl.Dispose();
    }
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SqlCeReplication クラス
SqlCeReplication メンバ
System.Data.SqlServerCe 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SqlCeReplication.BeginSynchronize」の関連用語

SqlCeReplication.BeginSynchronizeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SqlCeReplication.BeginSynchronizeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS