ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<!-- #include file="adovbs.inc" -->
<%
' 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 "<p><strong>Starting Transaction.</strong></p>" & vbCrLf
myConnection.BeginTrans
' Execute the SQL command 
Response.Write "<p><strong>Executing SQL Command:</strong><br /><code>" & strSqlQuery & "</code></p>" & vbCrLf
myConnection.Execute strSqlQuery, lngRecordsAffected, adCmdText + adExecuteNoRecords
' Echo back the number of records affected
Response.Write "<p><strong>Records Affected:</strong> <code>" & lngRecordsAffected & "</code></p>" & vbCrLf
' Either commit or rollback the transaction based on QueryString
If CBool(Request.QueryString("rollback")) = True Then
	Response.Write "<p><strong>Rolling Back Transaction.</strong></p>" & vbCrLf
	myConnection.RollbackTrans
Else
	Response.Write "<p><strong>Commiting Transaction.</strong></p>" & vbCrLf
	myConnection.CommitTrans
End If
' Close data access objects and free variables
myConnection.Close
Set myConnection = Nothing
%>
<br />
<p>
<strong>Run the script again:</strong>
<a href="<%= Request.ServerVariables("URL") %>?rollback=false">Commit Transaction</a>
or
<a href="<%= Request.ServerVariables("URL") %>?rollback=true">Rollback Transaction</a>
</p>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers