, .
. , .
- , ADO Connection.BeginTrans, .
- ( ADO Connection.CommitTrans).
- JRO.JetEngine.RefreshCache, .
, JRO.JetEngine Microsoft Jet Replication Objects 2.1 VB.
Sub SyncReadDemo()
Dim conn1 As New ADODB.Connection
Dim conn2 As New ADODB.Connection
Dim rs As New ADODB.recordset
Dim JRO As New JRO.JetEngine
Dim strConnect As String
Dim i As Long
' Set up our connection string (requires a database named c:\db1.mdb).
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db1.mdb"
' Open connection 1 and drop and re-create test table.
conn1.CursorLocation = adUseServer
conn1.Open strConnect
On Error Resume Next
conn1.Execute "drop table tmpTest", , _
adExecuteNoRecords + adCmdText
On Error GoTo 0
conn1.Execute "create table tmpTest (id long)", , _
adExecuteNoRecords + adCmdText
' Close connection 1 to flush the creation of table tmpTest.
conn1.Close
' Now open connection 1 and connection 2.
conn1.Open strConnect
conn2.Open strConnect
' Insert 10 records using connection 1.
' Note we must perform all writes inside of a transaction.
conn1.BeginTrans
For i = 1 To 10
conn1.Execute "insert into tmpTest (id) values (1)", , _
adExecuteNoRecords + adCmdText
Next i
conn1.CommitTrans
' Refresh cache for reader connection.
JRO.RefreshCache conn2
Set rs = conn2.Execute("select * from tmpTest", , adCmdText)
' Count records in our table (should be 10).
i = 0
While Not rs.EOF
i = i + 1
rs.MoveNext
Wend
rs.Close
MsgBox "Read " & i & " records using different connections."
conn1.Close
conn2.Close
End Sub