DbConflictType 열거형
동기화 중에 발생할 수 있는 충돌 유형을 정의합니다.
네임스페이스: Microsoft.Synchronization.Data
어셈블리: microsoft.synchronization.data.dll의 Microsoft.Synchronization.Data
구문
‘선언
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Enumeration DbConflictType
‘사용 방법
Dim instance As DbConflictType
[SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")]
public enum DbConflictType
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1706:ShortAcronymsShouldBeUppercase")]
public enum class DbConflictType
/** @attribute SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") */
public enum DbConflictType
SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")
public enum DbConflictType
멤버
멤버 이름 | 설명 | |
---|---|---|
ErrorsOccurred | 변경 내용을 적용하는 동안 피어 데이터베이스에서 예외를 발생시켰습니다. | |
LocalCleanedupDeleteRemoteUpdate | 원격 피어에서 업데이트한 행을 로컬 피어에서 삭제했고 해당 행의 메타데이터가 정리되었습니다. | |
LocalDeleteRemoteDelete | 로컬 및 원격 피어에서 모두 같은 행을 삭제했습니다. | |
LocalDeleteRemoteUpdate | 원격 피어에서 업데이트한 행을 로컬 피어에서 삭제했습니다. | |
LocalInsertRemoteInsert | 기본 키 값이 같은 행을 로컬 및 원격 피어에서 모두 삽입했습니다. 이로 인해 기본 키 위반이 발생했습니다. | |
LocalUpdateRemoteDelete | 원격 피어에서 삭제한 행을 로컬 피어에서 업데이트했습니다. | |
LocalUpdateRemoteUpdate | 로컬 및 원격 피어에서 모두 같은 행을 업데이트했습니다. |
주의
Sync Framework에서 충돌과 오류는 행 수준에서 검색됩니다. 충돌하는 행은 동기화 간에 둘 이상의 노드에서 변경된 행입니다. 동기화 중의 오류는 일반적으로 중복 기본 키와 같은 제약 조건 위반과 관련되어 있습니다. 자세한 내용은 방법: 공동 작업 동기화의 데이터 충돌 및 오류 처리(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