SqlCeReplication.CancelSynchronize Method

Cancels an ongoing asynchronous data synchronization that was started by calling the BeginSynchronize method.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

Syntax

'Declaration
Public Sub CancelSynchronize
'Usage
Dim instance As SqlCeReplication

instance.CancelSynchronize
public void CancelSynchronize ()
public:
void CancelSynchronize ()
public void CancelSynchronize ()
public function CancelSynchronize ()

Remarks

Canceling the synchronization is reported as an error with the error code SSCE_M_SYNCCANCELED. Canceling the synchronization only cancels the client-side operation; it does not send any request to cancel the ongoing server operation.

For information about asynchronous data synchronization in SQL Server Mobile, see "Asynchronous Data Synchronization" in the SQL Server Mobile Books Online.

Example

The following example shows how to cancel an ongoing data synchronization.

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 Security

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Platforms

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Compact Framework

Supported in: 2.0

See Also

Reference

SqlCeReplication Class
SqlCeReplication Members
System.Data.SqlServerCe Namespace