ReplicationServer.RegisterBusinessLogicHandler Method
Registers a business logic handler assembly at the replication server.
命名空間: Microsoft.SqlServer.Replication
組件: Microsoft.SqlServer.Rmo (in microsoft.sqlserver.rmo.dll)
語法
'宣告
Public Sub RegisterBusinessLogicHandler ( _
businessLogicHandler As BusinessLogicHandler _
)
public void RegisterBusinessLogicHandler (
BusinessLogicHandler businessLogicHandler
)
public:
void RegisterBusinessLogicHandler (
BusinessLogicHandler^ businessLogicHandler
)
public void RegisterBusinessLogicHandler (
BusinessLogicHandler businessLogicHandler
)
public function RegisterBusinessLogicHandler (
businessLogicHandler : BusinessLogicHandler
)
參數
- businessLogicHandler
A BusinessLogicHandler object that represents the business logic handler being registered.
備註
The business logic handler must be registered at the Publisher and at the server on which the Merge Agent runs. However, the assembly that implements the business logic handler need only be installed on the server on which the Merge Agent runs.
The RegisterBusinessLogicHandler method can only be called by members of the sysadmin fixed server role and members of the db_owner fixed database role
Calling RegisterBusinessLogicHandler is equivalent to executing sp_registercustomresolver (Transact-SQL).
The RegisterBusinessLogicHandler method can only be used with servers running on SQL Server 2005 and later releases.
範例
// Specify the Distributor name and business logic properties.
string distributorName = publisherInstance;
string assemblyName = @"C:\Program Files\Microsoft SQL Server\90\COM\CustomLogic.dll";
string className = "Microsoft.Samples.SqlServer.BusinessLogicHandler.OrderEntryBusinessLogicHandler";
string friendlyName = "OrderEntryLogic";
ReplicationServer distributor;
BusinessLogicHandler customLogic;
// Create a connection to the Distributor.
ServerConnection distributorConn = new ServerConnection(distributorName);
try
{
// Connect to the Distributor.
distributorConn.Connect();
// Set the Distributor properties.
distributor = new ReplicationServer(distributorConn);
// Set the business logic handler properties.
customLogic = new BusinessLogicHandler();
customLogic.DotNetAssemblyName = assemblyName;
customLogic.DotNetClassName = className;
customLogic.FriendlyName = friendlyName;
customLogic.IsDotNetAssembly = true;
Boolean isRegistered = false;
// Check if the business logic handler is already registered at the Distributor.
foreach (BusinessLogicHandler registeredLogic
in distributor.EnumBusinessLogicHandlers())
{
if (registeredLogic == customLogic)
{
isRegistered = true;
}
}
// Register the custom logic.
if (!isRegistered)
{
distributor.RegisterBusinessLogicHandler(customLogic);
}
}
catch (Exception ex)
{
// Do error handling here.
throw new ApplicationException(string.Format(
"The {0} assembly could not be registered.",
assemblyName), ex);
}
finally
{
distributorConn.Disconnect();
}
' Specify the Distributor name and business logic properties.
Dim distributorName As String = publisherInstance
Dim assemblyName As String = "C:\Program Files\Microsoft SQL Server\90\COM\CustomLogic.dll"
Dim className As String = "Microsoft.Samples.SqlServer.BusinessLogicHandler.OrderEntryBusinessLogicHandler"
Dim friendlyName As String = "OrderEntryLogic"
Dim distributor As ReplicationServer
Dim customLogic As BusinessLogicHandler
' Create a connection to the Distributor.
Dim distributorConn As ServerConnection = New ServerConnection(distributorName)
Try
' Connect to the Distributor.
distributorConn.Connect()
' Set the Distributor properties.
distributor = New ReplicationServer(distributorConn)
' Set the business logic handler properties.
customLogic = New BusinessLogicHandler()
customLogic.DotNetAssemblyName = assemblyName
customLogic.DotNetClassName = className
customLogic.FriendlyName = friendlyName
customLogic.IsDotNetAssembly = True
Dim isRegistered As Boolean = False
' Check if the business logic handler is already registered at the Distributor.
For Each registeredLogic As BusinessLogicHandler _
In distributor.RegisteredSubscribers
If registeredLogic Is customLogic Then
isRegistered = True
End If
Next
' Register the custom logic.
If Not isRegistered Then
distributor.RegisterBusinessLogicHandler(customLogic)
End If
Catch ex As Exception
' Do error handling here.
Throw New ApplicationException(String.Format( _
"The {0} assembly could not be registered.", _
assemblyName), ex)
Finally
distributorConn.Disconnect()
End Try
執行緒安全性
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
平台
開發平台
如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。
目標平台
如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。
請參閱
參考
ReplicationServer Class
ReplicationServer Members
Microsoft.SqlServer.Replication Namespace
其他資源
在合併同步處理期間執行商務邏輯
How to: Implement a Business Logic Handler for a Merge Article (RMO Programming)