Поделиться через


Свойство DbApplyChangeFailedEventArgs.Action

Возвращает или задает значение перечисления ApplyAction, которое указывает действие, выполняемое при разрешении конфликта.

Пространство имен: Microsoft.Synchronization.Data
Сборка: Microsoft.Synchronization.Data (в microsoft.synchronization.data.dll)

Синтаксис

'Декларация
Public Property Action As ApplyAction
'Применение
Dim instance As DbApplyChangeFailedEventArgs
Dim value As ApplyAction

value = instance.Action

instance.Action = value
public ApplyAction Action { get; set; }
public:
property ApplyAction Action {
    ApplyAction get ();
    void set (ApplyAction value);
}
/** @property */
public ApplyAction get_Action ()

/** @property */
public void set_Action (ApplyAction value)
public function get Action () : ApplyAction

public function set Action (value : ApplyAction)

Значение свойства

Значение перечисления ApplyAction, указывающее действие, выполняемое при разрешении конфликта.

Замечания

Если при синхронизации строка не может быть применена, то вызывается событие ApplyChangeFailed. Объект DbApplyChangeFailedEventArgs содержит сведения об ошибке или конфликте, которые привели к сбою операции. Обработчик события может обработать событие несколькими различными способами, например, указав службе синхронизации, что строку необходимо попытаться применить повторно. Дополнительные сведения см. в разделе Как обрабатывать конфликты и ошибки в данных для синхронизации совместной работы (SQL Server).

Пример

В следующих примерах кода показана обработка конфликтов типа «обновление-обновление» в обработчике события ApplyChangeFailed. В этом примере конфликтующие строки выводятся на консоль с параметром, который должен определить, в пользу какой строки разрешается конфликт. Чтобы просмотреть этот код в контексте полного примера, см. раздел Как обрабатывать конфликты и ошибки в данных для синхронизации совместной работы (SQL Server).

localProvider.ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(dbProvider_ApplyChangeFailed);
remoteProvider.ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(dbProvider_ApplyChangeFailed);
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.");
    }
}
AddHandler localProvider.ApplyChangeFailed, AddressOf dbProvider_ApplyChangeFailed
AddHandler remoteProvider.ApplyChangeFailed, AddressOf dbProvider_ApplyChangeFailed
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.
    Dim i As Integer
    For i = 0 To localColumnCount - 1
        Console.Write(conflictingLocalChange.Rows(0)(i).ToString & " | ")
    Next 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 i = 0 To remoteColumnCount - 1
        Console.Write(conflictingRemoteChange.Rows(0)(i).ToString & " | ")
    Next 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.")

    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

См. также

Справочник

Класс DbApplyChangeFailedEventArgs
Элементы DbApplyChangeFailedEventArgs
Пространство имен Microsoft.Synchronization.Data