<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %> <% ' ADO constants included above. Questions about adovbs.inc? ' See "What is Adovbs.inc and Why Do I Need It?" ' http://www.asp101.com/articles/john/adovbs/default.asp Dim strConnString ' Connection string Dim myConnection ' ADO Connection object Dim strSqlQuery ' SQL query Dim lngRecordsAffected ' Number of records affected by command ' Set our connection string strConnString = "Provider=SQLOLEDB;Data Source=10.2.2.133;" _ & "Initial Catalog=samples;User Id=samples;Password=password;" _ & "Connect Timeout=15;Network Library=dbmssocn;" ' Build our SQL query strSqlQuery = "INSERT INTO [scratch] (text_field, integer_field, date_time_field) " _ & "VALUES ('" _ & CStr(WeekdayName(WeekDay(Date()))) & "', '" _ & CInt(Day(Now())) & "', '" _ & Now() & "');" ' Open connection Set myConnection = Server.CreateObject("ADODB.Connection") myConnection.Open strConnString ' Start transaction Response.Write "

Starting Transaction.

" & vbCrLf myConnection.BeginTrans ' Execute the SQL command Response.Write "

Executing SQL Command:
" & strSqlQuery & "

" & vbCrLf myConnection.Execute strSqlQuery, lngRecordsAffected, adCmdText + adExecuteNoRecords ' Echo back the number of records affected Response.Write "

Records Affected: " & lngRecordsAffected & "

" & vbCrLf ' Either commit or rollback the transaction based on QueryString If CBool(Request.QueryString("rollback")) = True Then Response.Write "

Rolling Back Transaction.

" & vbCrLf myConnection.RollbackTrans Else Response.Write "

Commiting Transaction.

" & vbCrLf myConnection.CommitTrans End If ' Close data access objects and free variables myConnection.Close Set myConnection = Nothing %>

Run the script again: ?rollback=false">Commit Transaction or ?rollback=true">Rollback Transaction