📄 sample vb resolver(
字号:
作者:怡红公子
email: luckyangel@163.net
日期:2001-6-30 10:37:03
SQL 2000中合并复制有很强大的冲突解决方案,其中除了SQL2k自己定义的以外,还可以使用VB/VC来自己编写冲突解决方案。(参见ppt文档)
下面是使用VB的一个Demo,ppt文档中有提到的。
[hr]
'=====================================================================
' This file is part of the Microsoft SQL Server replication Code Samples.
'
' Copyright (C) 1999-2001 Microsoft Corporation. All rights reserved.
'
' This source code is intended only as a supplement to Microsoft
' Development Tools and/or on-line documentation. See these other
' materials for detailed information regarding Microsoft code samples.
'
' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
' KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
' IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'=====================================================================
'---------------------------------------------------
' IVBCustomResolver_GetHandledStates
' This method returns the set of states that are
' handled by the custom resolver - This resolver
' handles update conflicts only.
'---------------------------------------------------
Public Sub IVBCustomResolver_GetHandledStates(ByRef pResolverBm As Long)
Dim rct As SQLResolver.REPOLE_CHANGE_TYPE
rct = REPOLEChange_SubscriberUpdate_ConflictColTrack Or _
REPOLEChange_PublisherUpdate_ConflictColTrack Or _
REPOLEChange_PublisherUpdate_ConflictNoColTrack Or _
REPOLEChange_PublisherUpdate_ConflictColTrack
pResolverBm = rct
End Sub
'---------------------------------------------------
' IVBCustomResolver_Reconcile
' This method is invoked by the merge process whenever
' an update conflict has been encountered.
'---------------------------------------------------
Public Sub IVBCustomResolver_Reconcile
(ByVal rrc As IReplRowChange,
ByVal dwFlags As Long,
ByVal rrcSugg As IReplRowChange)
IVBCustomResolver_ComputeMinimumValue:
' Get the Publisher's value for the resolver column into PublisherData
' Get the Subscriber' value for the resolver column into SubscriberData
If SrcIsPublisher Then
rrc.GetSourceColumnValue iColumn, PublisherData, 0&, 0&
rrc.GetDestinationColumnValue iColumn, SubscriberData, 0&, 0&
Else
rrc.GetSourceColumnValue iColumn, SubscriberData, 0&, 0&
rrc.GetDestinationColumnValue iColumn, PublisherData, 0&, 0&
End If
' Compute the minimum value and use that to chose the winner as the
' source or the destination. If the Publisher and Subscriber data
' values match choose the winner based on priorities.
' Case 1: PublisherData < SubscriberData
If PublisherData < SubscriberData Then
ResolvedData = PublisherData
If SrcIsPublisher Then
WinnerPriority = REPOLEPriority_Source
Else
WinnerPriority = REPOLEPriority_Destination
End If
' Case 2: PublisherData > SubscriberData
ElseIf SubscriberData < PublisherData Then
ResolvedData = SubscriberData
If DestIsPublisher Then
WinnerPriority = REPOLEPriority_Source
Else
WinnerPriority = REPOLEPriority_Destination
End If
' Case 3: PublisherData = SubscriberData
Else
ResolvedData = PublisherData
rrc.GetPriorityWinner WinnerPriority
End If
' If the winner is not the source just exit - the winner will be chosen
' on the next phase
If WinnerPriority <> REPOLEPriority_Source Then
GoTo IVBCustomResolver_Reconcile_Exit
Else
' Log the destination's update as a conflict loser and
' Propagate the source's update as the winning value.
rrc.LogConflict False, REPOLEConflict_UpdateConflict, True
rrc.CopyRowFromSource
End If
' Display an infomational message indicating the resolution.
Select Case ChangeType
Case REPOLEChange_SubscriberUpdate_ConflictColTrack, _
REPOLEChange_PublisherUpdate_ConflictColTrack, _
REPOLEChange_SubscriberUpdate_ConflictNoColTrack, _
REPOLEChange_PublisherUpdate_ConflictNoColTrack
stMessage = "The column " & stResolverColumn & " was updated at the Publisher (" & _
stPublisher & ":" & stPublisherDB & ") to value : " & CStr(PublisherData) & _
" and the Subscriber (" & stSubscriber & ":" & stSubscriberDB & ") to value : " & CStr(SubscriberData) & _
". The resolver chose the row with column value " & CStr(ResolvedData) & " as the winner."
Case Else
stMessage = msgUnhandledConflict
End Select
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -