Article ID: 198024
Article Last Modified on 10/31/2003
set implicit_transactions on go insert insert insertis internally turned into
BEGIN TRAN Insert insert insert ...The above transaction will not be rolled back or committed unless the user issues the correct statement.
begin tran insert commit tran begin tran insert commit tran ...The following code sequence, written in Visual Basic, shows a difference between the raw SQL "BEGIN TRANSACTION" and the "set implicit_transactions on" issued when the ADO connection method BeginTrans is invoked:
Command1.Caption : Use ADO Transactions
Command2.Caption : Use T-SQL Transactions
Microsoft ActiveX Data Objects 2.0 Library
Option Explicit
Dim Cn As New ADODB.Connection
Dim Cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Private Sub Command1_Click()
Cn.Execute "Delete from stores where stor_id LIKE '1%'"
Cn.BeginTrans
Cn.Execute "set implicit_transactions off"
Cn.Execute "Insert INTO Stores(stor_id, _
stor_name,stor_address,city)" & _
"VALUES(101,'Store One','123 Oak St.','Seattle')"
Cn.Execute "Insert INTO Stores(stor_id, _
stor_name,stor_address,city)" & _
"VALUES(102,'Store Two','123 Main St.','Tacoma')"
Cn.RollbackTrans
With rst
.ActiveConnection = Cn
.CursorType = adOpenStatic
.Source = "select * from stores where stor_id LIKE '10%'"
.Open
End With
MsgBox rst.RecordCount
rst.Close
End Sub
Private Sub Command2_Click()
Cn.Execute "Delete from stores where stor_id LIKE '1%'"
Cn.Execute "BEGIN TRANSACTION"
Cn.Execute "set implicit_transactions off"
Cn.Execute "Insert INTO Stores (stor_id, _
stor_name,stor_address,city)" & _
"VALUES(101,'Store One','123 Oak St.','Seattle')"
Cn.Execute "Insert INTO Stores (stor_id, _
stor_name,stor_address,city)" & _
"VALUES(102,'Store Two','123 Main St.','Tacoma')"
Cn.Execute "ROLLBACK TRANSACTION"
With rst
.ActiveConnection = Cn
.CursorType = adOpenStatic
.Source = "select * from stores where stor_id LIKE '10%'"
.Open
End With
MsgBox rst.RecordCount
rst.Close
End Sub
Private Sub Form_Load()
Dim strConn As String
strConn = "Provider=SQLOLEDB;User ID=<username>;Password=<strong password>;Data" & _
"Source=(local);database=pubs"
Cn.Open strConn
Cn.CursorLocation = adUseClient
Command1.Caption = "Use ADO Transactions"
Command2.Caption = "Use T-SQL Transactions"
End Sub
FETCH ALTER TABLE DELETE INSERT CREATE OPEN GRANT REVOKE DROP TRUNCATE TABLE SELECT UPDATEWhen this option (set implicit_transactions on) is turned on and if there are no outstanding transactions, every ANSI SQL statement will automatically start a transaction. If there is an open transaction, no new transaction will be started. This transaction has to be explicitly committed by the user by using the command COMMIT TRANSACTION for the changes to take affect and the locks to be released.
177138 INFO: Nested Transactions Not Available in ODBC/OLE DB/ADO
Additional query words: kbSQLServer700
Keywords: kbinfo kbdatabase kbcode KB198024