Article ID: 187942
Article Last Modified on 3/2/2005
-or-
rs.Properties("Preserve On Commit") = True
rs.Properties("Preserve On Abort") = True
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cn.Open "provider=SQLOLEDB;data source=<server>;initial " _
& "catalog=pubs;user id=<user id>;password=<password>"
' error handling for non-existent Test1 table
On Error Resume Next
cn.Execute "drop table Test1"
On Error GoTo 0
cn.Execute "create table Test1(id int primary key, num int)"
For i = 1 To 10
cn.Execute "insert into Test1 values(" & i & ", " & i & ")"
Next i
Set rst.ActiveConnection = cn
'Set these properties to True to prevent error.
'rst.Properties("Preserve On Commit") = True
'rst.Properties("Preserve On Abort") = True
cn.BeginTrans
rst.Open "select * from Test1", , adOpenStatic, adLockOptimistic
Debug.Print rst(0)
cn.RollbackTrans
' If the preserve properties are not set, the following fails
Debug.Print rst(0)
Keywords: kbprovider kbdatabase kbprb KB187942