Compartir a través de


DbApplyChangeFailedEventArgs.Conflict Propiedad

Obtiene un objeto DbSyncConflict que contiene los datos y metadatos correspondientes a la fila que se va a aplicar y a la fila existente en la base de datos causante del error.

Espacio de nombres: Microsoft.Synchronization.Data
Ensamblado: Microsoft.Synchronization.Data (en microsoft.synchronization.data.dll)

Sintaxis

'Declaración
Public ReadOnly Property Conflict As DbSyncConflict
'Uso
Dim instance As DbApplyChangeFailedEventArgs
Dim value As DbSyncConflict

value = instance.Conflict
public DbSyncConflict Conflict { get; }
public:
property DbSyncConflict^ Conflict {
    DbSyncConflict^ get ();
}
/** @property */
public DbSyncConflict get_Conflict ()
public function get Conflict () : DbSyncConflict

Valor de la propiedad

Objeto DbSyncConflict que contiene metadatos y datos de conflictos.

Notas

Si una fila no puede aplicarse durante la sincronización, se genera el evento ApplyChangeFailed. El objeto DbApplyChangeFailedEventArgs proporciona información sobre el error o conflicto que ha producido el error. En un controlador del evento, puede responder al evento de varias formas, incluso especificar si es necesario que el proveedor de sincronización vuelva a aplicar la fila. Para obtener más información, vea Tratar los conflictos de datos y los errores de la sincronización de colaboración (SQL Server).

Si una aplicación debe cambiar valores de datos durante la sincronización, utilice el objeto DbSyncContext que está disponible a través de la propiedad Context, en lugar del objeto DbSyncConflict. El objeto DbSyncConflict contiene copias de las filas en cada elemento del mismo nivel. Los cambios efectuados en estas copias no se conservan en cada elemento del mismo nivel durante la sincronización.

Ejemplo

En los ejemplos de código siguientes se muestra cómo se pueden procesar los conflictos de actualización-actualización en un controlador del evento ApplyChangeFailed. En el ejemplo, las filas en conflicto se muestran en la consola con una opción para especificar qué fila debe prevalecer en el conflicto. Para consultar este código en el contexto de un ejemplo completo, vea Tratar los conflictos de datos y los errores de la sincronización de colaboración (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

Vea también

Referencia

DbApplyChangeFailedEventArgs Clase
DbApplyChangeFailedEventArgs Miembros
Microsoft.Synchronization.Data Espacio de nombres