Publish date: 2003-01-17

ActiveX Components. Clone of connection in ADODB (VB)

'Sample of work with ActiveX component 'IBPSamples.TADOConnectionClone'
'1 download _ibp_sample_obj.dll from www.ibprovider.com
'2 execute: regsvr32 _ibp_sample_obj.dll
'3 add in your VB-project the reference to 'LCPI - IBProvider Samples' library

Sub sample_9_2()
 Dim cn1       As New ADODB.Connection
 Dim cn_clone  As New IBPSamples.TADOConnectionClone

 cn1.Provider = "LCPI.IBProvider"
 cn1.Open "main:e:\database\employee.gdb", "gamer", "vermut"

 cn_clone.Connection = cn1

 'build ADOConnection object for exists connection, but separate transaction
 Dim cn2 As ADODB.Connection

 Set cn2 = cn_clone.Clone

 'Check that we work in different transactions

 cn1.BeginTrans
 cn2.BeginTrans

 Dim cmd1 As New ADODB.Command
 Dim cmd2 As New ADODB.Command

 cmd1.ActiveConnection = cn1
 cmd2.ActiveConnection = cn2

 'TRANS 1: insert new country
 cmd1.CommandText = "insert into country (country,currency) values(:a,:b)"
 cmd1("a") = "Mars"
 cmd1("b") = "Snickers"

 cmd1.Execute

 'TRANS 2: select mars+snickers
 cmd2.CommandText = "select count(*) from country where country=:a and currency=:b"

 cmd2("a").Value = cmd1("a").Value
 cmd2("b").Value = cmd1("b").Value

 If (cmd2.Execute.Fields(0).Value <> 0) Then Err.Raise -1, , "BUG: We select NOT EMPTY recordset"

 Debug.Print "OK"
End Sub 'sample_9_2