Classe DbApplyChangeFailedEventArgs

Fornece dados para o evento ApplyChangeFailed.

Namespace: Microsoft.Synchronization.Data
Assembly: Microsoft.Synchronization.Data (em microsoft.synchronization.data.dll)

Sintaxe

'Declaração
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Class DbApplyChangeFailedEventArgs
    Inherits EventArgs
'Uso
Dim instance As DbApplyChangeFailedEventArgs
[SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")] 
public class DbApplyChangeFailedEventArgs : EventArgs
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1706:ShortAcronymsShouldBeUppercase")] 
public ref class DbApplyChangeFailedEventArgs : public EventArgs
/** @attribute SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") */ 
public class DbApplyChangeFailedEventArgs extends EventArgs
SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") 
public class DbApplyChangeFailedEventArgs extends EventArgs

Comentários

Se não for possível aplicar uma linha durante a sincronização, será gerado o evento ApplyChangeFailed. O objeto DbApplyChangeFailedEventArgs fornece informações sobre o erro ou o conflito que provocou a falha. Em um manipulador do evento, você pode responder ao evento de várias maneiras, inclusive especificando se o provedor de sincronização deve tentar aplicar a linha novamente. Para obter mais informações, consulte Como manipular conflitos de dados e erros de sincronização de colaboração (SQL Server).

Exemplo

O exemplo de código a seguir mostra como podem ser processados conflitos de atualização/atualização em um manipulador de eventos ApplyChangeFailed. No exemplo, as linhas conflitantes são exibidas no console com uma opção para especificar qual linha deveria ganhar o conflito. Para exibir esse código no contexto de um exemplo completo, consulte Como manipular conflitos de dados e erros de sincronização de colaboração (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

Hierarquia de herança

System.Object
   System.EventArgs
    Microsoft.Synchronization.Data.DbApplyChangeFailedEventArgs

Segurança de thread

Qualquer membro estático público (Compartilhado no Visual Basic) deste tipo é protegido por thread. Não há garantia de que qualquer membro de instância esteja protegido por thread.

Consulte também

Referência

Membros DbApplyChangeFailedEventArgs
Namespace Microsoft.Synchronization.Data