|
This section describes how Pervasive's OLE DB provider interacts with Microsoft's COM+ Services.
COM+ services (Component Object Model) is a Microsoft specific technology used to create business objects in a multi-threaded context. COM+ is primarily designed for, but not limited to, Visual Basic programmers. COM+ allows for rapid creation of multi-tier applications and includes many benefits that would normally have to be implemented by the developer. The benefits of COM+ include
For further information about COM+, see Microsoft's documentation.
COM+ services are an extension to the benefits provided by MTS (Microsoft Transaction Server). MTS is Microsoft's previous business object server implementation. In general, references (in Microsoft and Pervasive documentation) to MTS can be substituted with COM+ services.
Pervasive's OLE DB provider is supported in COM+ services. ADO calls made within COM+ services behave like any ADO client call.
As a Visual Basic programmer, you must be aware of the MTSTransactionMode property. Setting this to anything other than NoTransactions will invoke Microsoft transactions. Please refer to COM+ services documentation for the complete reference of this feature.
The following example demonstrates use of Microsoft Transactions. In order for the calls to GetObjectContext to succeed, you must set the MTSTransactionMode property to something other than NoTransactions. Using Microsoft Transactions will allow Microsoft's Transaction Coordinator to do a two-phase commit.
Public Function UpdatePayroll(employeeID As Integer, salary As Currency) On Error GoTo ErrHandler Dim rs As New ADODB.Recordset rs.Index = "employeeID" rs.Open "PayrollTable", "Provider=PervasiveOLEDB;Data Source=CompanyDB", adOpenDynamic, adLockOptimistic, adCmdTableDirect rs.Seek employeeID, adSeekFirstEQ If rs.EOF = True Then GetObjectContext.SetAbort Else rs!salary = salary End If rs.Update rs.Close rs = Nothing GetObjectContext.SetComplete Exit Function ErrHandler: GetObjectContext.SetAbort If Not IsNull(rs) Then If rs.State = adStateOpen Then rs.Close End If End If rs = Nothing End Function
However, you could rewrite this business object using ADO transactions (with a connection object). This would allow you to set the MTSTransactionMode property to NoTransactions. Without Microsoft Transactions, you no longer have the overhead of the two-phase commit. Also, objects that do not support transactions are allowed to stay resident in memory, whereas those that do are constructed and destroyed on each reference.
Public Function UpdatePayroll(employeeID As Integer, salary As Currency) On Error GoTo ErrHandler Dim cn As New Connection Dim rs As New ADODB.Recordset cn.Open "Provider=PervasiveOLEDB;Data Source=CompanyDB" cn.BeginTrans rs.Index = "employeeID" rs.Open "PayrollTable", cn, adOpenDynamic, adLockOptimistic, adCmdTableDirect rs.Seek employeeID, adSeekFirstEQ If rs.EOF = True Then cn.RollbackTrans Else rs!salary = salary End If rs.Update rs.Close cn.CommitTrans Exit Function ErrHandler: cn.RollbackTrans If Not IsNull(rs) Then If rs.State = adStateOpen Then rs.Close End If End If End Function
|
Chapter contents
Prev topic: Programming Notes for Pervasive OLE DB Provider
|