Share via


ApplyChangeFailed-Ereignis

Tritt während des Hochladens auf, nachdem eine Zeile nicht auf einen Knoten angewendet werden konnte.

Namespace:  Microsoft.Synchronization.Data
Assembly:  Microsoft.Synchronization.Data (in Microsoft.Synchronization.Data.dll)

Syntax

'Declaration
Public Event ApplyChangeFailed As EventHandler(Of DbApplyChangeFailedEventArgs)
'Usage
Dim instance As RelationalSyncProvider
Dim handler As EventHandler(Of DbApplyChangeFailedEventArgs)

AddHandler instance.ApplyChangeFailed, handler
public event EventHandler<DbApplyChangeFailedEventArgs> ApplyChangeFailed
public:
 event EventHandler<DbApplyChangeFailedEventArgs^>^ ApplyChangeFailed {
    void add (EventHandler<DbApplyChangeFailedEventArgs^>^ value);
    void remove (EventHandler<DbApplyChangeFailedEventArgs^>^ value);
}
member ApplyChangeFailed : IEvent<EventHandler<DbApplyChangeFailedEventArgs>,
    DbApplyChangeFailedEventArgs>

Hinweise

Wenn eine Zeile während der Synchronisierung nicht angewendet werden kann, wird das ApplyChangeFailed-Ereignis ausgelöst. Das DbApplyChangeFailedEventArgs-Objekt stellt Informationen über den Fehler oder Konflikt zur Verfügung, der zur Auslösung des Ereignisses geführt hat. In einem Handler für das Ereignis können Sie auf verschiedene Art und Weise auf das Ereignis reagieren. So können Sie z. B. festlegen, ob der Synchronisierungsanbieter erneut versuchen soll, die Zeile zu übernehmen. Weitere Informationen finden Sie unter Vorgehensweise: Behandeln von Datenkonflikten und Fehlern bei der Datenbanksynchronisierung (SQL Server).

Beispiele

Im folgenden Codebeispiel wird gezeigt, wie Aktualisierungskonflikte in einem ApplyChangeFailed-Ereignishandler verarbeitet werden können. In dem Beispiel werden die miteinander in Konflikt stehenden Zeilen in der Konsole mit der Auswahlmöglichkeit angezeigt, welche Zeile in dem Konflikt Vorrang haben soll. Eine Darstellung dieses Codes im Kontext eines vollständigen Beispiels finden Sie unter Vorgehensweise: Behandeln von Datenkonflikten und Fehlern bei der Datenbanksynchronisierung (SQL Server).

if (e.Conflict.Type == DbConflictType.LocalUpdateRemoteUpdate)
{

    //Get the conflicting changes from the Conflict object
    //and display them. The Conflict object holds a copy
    //of the changes; updates to this object will not be 
    //applied. To make changes, use the Context object.
    DataTable conflictingRemoteChange = e.Conflict.RemoteChange;
    DataTable conflictingLocalChange = e.Conflict.LocalChange;
    int remoteColumnCount = conflictingRemoteChange.Columns.Count;
    int localColumnCount = conflictingLocalChange.Columns.Count;

    Console.WriteLine(String.Empty);
    Console.WriteLine(String.Empty);
    Console.WriteLine("Row from database " + DbConflictDetected);
    Console.Write(" | ");

    //Display the local row. As mentioned above, this is the row
    //from the database at which the conflict was detected.
    for (int i = 0; i < localColumnCount; i++)
    {
        Console.Write(conflictingLocalChange.Rows[0][i] + " | ");
    }

    Console.WriteLine(String.Empty);
    Console.WriteLine(String.Empty);
    Console.WriteLine(String.Empty);
    Console.WriteLine("Row from database " + DbOther);
    Console.Write(" | ");

    //Display the remote row.
    for (int i = 0; i < remoteColumnCount; i++)
    {
        Console.Write(conflictingRemoteChange.Rows[0][i] + " | ");
    }

    //Ask for a conflict resolution option.
    Console.WriteLine(String.Empty);
    Console.WriteLine(String.Empty);
    Console.WriteLine("Enter a resolution option for this conflict:");
    Console.WriteLine("A = change from " + DbConflictDetected + " wins.");
    Console.WriteLine("B = change from " + DbOther + " wins.");

    string conflictResolution = Console.ReadLine();
    conflictResolution.ToUpper();

    if (conflictResolution == "A")
    {
        e.Action = ApplyAction.Continue;
    }

    else if (conflictResolution == "B")
    {
        e.Action = ApplyAction.RetryWithForceWrite;
    }

    else
    {
        Console.WriteLine(String.Empty);
        Console.WriteLine("Not a valid resolution option.");
    }
}
If e.Conflict.Type = DbConflictType.LocalUpdateRemoteUpdate Then

    'Get the conflicting changes from the Conflict object 
    'and display them. The Conflict object holds a copy 
    'of the changes; updates to this object will not be 
    'applied. To make changes, use the Context object. 
    Dim conflictingRemoteChange As DataTable = e.Conflict.RemoteChange
    Dim conflictingLocalChange As DataTable = e.Conflict.LocalChange
    Dim remoteColumnCount As Integer = conflictingRemoteChange.Columns.Count
    Dim localColumnCount As Integer = conflictingLocalChange.Columns.Count

    Console.WriteLine([String].Empty)
    Console.WriteLine([String].Empty)
    Console.WriteLine("Row from database " & DbConflictDetected)
    Console.Write(" | ")

    'Display the local row. As mentioned above, this is the row 
    'from the database at which the conflict was detected. 
    For i As Integer = 0 To localColumnCount - 1
        Console.Write(conflictingLocalChange.Rows(0)(i).ToString() & " | ")
    Next

    Console.WriteLine([String].Empty)
    Console.WriteLine([String].Empty)
    Console.WriteLine([String].Empty)
    Console.WriteLine("Row from database " & DbOther)
    Console.Write(" | ")

    'Display the remote row. 
    For i As Integer = 0 To remoteColumnCount - 1
        Console.Write(conflictingRemoteChange.Rows(0)(i).ToString() & " | ")
    Next

    'Ask for a conflict resolution option. 
    Console.WriteLine([String].Empty)
    Console.WriteLine([String].Empty)
    Console.WriteLine("Enter a resolution option for this conflict:")
    Console.WriteLine("A = change from " & DbConflictDetected & " wins.")
    Console.WriteLine("B = change from " & DbOther & " wins.")

    Dim conflictResolution As String = Console.ReadLine()
    conflictResolution.ToUpper()

    If conflictResolution = "A" Then
        e.Action = ApplyAction.Continue

    ElseIf conflictResolution = "B" Then
        e.Action = ApplyAction.RetryWithForceWrite
    Else

        Console.WriteLine([String].Empty)
        Console.WriteLine("Not a valid resolution option.")
    End If

Siehe auch

Verweis

RelationalSyncProvider Klasse

RelationalSyncProvider-Member

Microsoft.Synchronization.Data-Namespace