Microsoft Knowledge Base Email Alertz

This step-by-step procedure demonstrates how to process data transactions from an Active Server Pages (ASP) page if the transactions use ActiveX Data Objects (ADO) to connect to a database.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 299637 - Last Review: December 14, 2011 - Revision: 4.0

How To Process Data Transactions from an ASP Page

This article was previously published under Q299637

On This Page

SUMMARY

This step-by-step procedure demonstrates how to process data transactions from an Active Server Pages (ASP) page if the transactions use ActiveX Data Objects (ADO) to connect to a database.

Prerequisites

This list outlines the recommended hardware, software, network infrastructure, and service packs that you will need:

  • Microsoft Active Server Pages
  • Microsoft Internet Information Server
This article assumes that you are familiar with the following topics:

  • ASP terminology and syntax
  • Data Access technologies (Microsoft ActiveX Data Objects)

Processing Data Transactions from ASP

  1. In Notepad, create a new ASP page named DataTran.asp, and paste the following code:

    Note You must change UID=<username> and pwd=<strong password> to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.
    <%@ TRANSACTION=Required%>
    <%
    	Option Explicit
            On Error Resume Next
    	Dim oConn, oRS
    		
    	Set oConn = Server.CreateObject("ADODB.Connection")
    	oConn.Open "Provider=SQLOleDB;server=servername;Initial Catalog=pubs;uid=<username>;pwd=<strong password>"	
    	if err.Number <> 0 Then
    	    Response.Write "<BR>Error Occurred Opening Connection...<BR>"
    	    Response.Write "<BR>Error Description: " & err.Description & "...<BR>"
                ObjectContext.SetAbort
    	    Response.End
    	else
    	    Response.Write "Connection Opened Successfully...<BR>"
    	    ObjectContext.SetComplete
    	End If
    
    	
       	oConn.Execute "Select * from Authors"
    	if err.Number <> 0 Then
    	    Response.Write "<BR>Error Occurred Executing Query...<BR>"
    	    Response.Write "<BR>Error Description: " & err.Description & "...<BR>"
    	    oConn.Close
    	    Set oConn = Nothing
                ObjectContext.SetAbort
                Response.End
    	else
    	    Response.Write "<BR>Query Completed Successfully...<BR>"
    	    ObjectContext.SetComplete
    	End If
    
    	oConn.Close
    	Response.Write "<BR>Connection Closed Successfully...<BR>"
    	set oConn = Nothing
    	Response.Write "<BR>Test Completed Successfully...<BR>"
    
        Sub OnTransactionCommit()
            	Response.Write "<p><b>The Transaction just committed</b>." 
    	Response.Write "This message came from the "
            	Response.Write "OnTransactionCommit() event handler."
        End Sub
    
        Sub OnTransactionAbort()
            	Response.Write "<p><b>The Transaction just aborted</b>." 
            	Response.Write "This message came from the "
            	Response.Write "OnTransactionAbort() event handler."
        End Sub
    
    %>
    					
  2. The above code sample tries to connect to the Microsoft SQL Server default PUBS database. If you do not have SQL Server installed, you must change the connection string and the SQL statement.

    Also, make sure that you change the connection string in the following line of code to include the correct server name, User Id (UID) and Password (PWD):
    	oConn.Open "Provider=SQLOleDB;server=servername;Initial Catalog=pubs;uid=<username>;pwd=<strong password>"
    					
  3. On the File menu, click Save. In the Save in drop-down list box, click the C:\Inetpub\Wwwroot folder. In the Save as type drop-down list box, click All Files. In the File name list box, type DataTran.asp.
  4. In your Web browser, run the ASP page (for example, http://localhost/DataTran.asp).
  5. If the OLE DB connection string and query are valid, the following output is returned:
    Connection Opened Successfully...
    
    Query Completed Successfully...
    
    Connection Closed Successfully...
    
    Test Completed Successfully...
    
    The Transaction just committed.This message came from the 
    OnTransactionCommit() event handler.
    						
  6. If the OLE DB connection string is invalid, or if your query is incorrect, you receive an error message, and the OnTransactionAbort event is fired. The following output is returned:
    Connection Opened Successfully...
    
    Error Occurred Executing Query...
    
    Error Description: Invalid object name 'Author'....
    
    The Transaction just aborted.This message came from the 
    OnTransactionAbort() event handler.
    						
    NOTE: In Internet Information Services (IIS) 7.0 and later, OnTransactionAbort() is not called if you call Response.End after ObjectContext.SetAbort.

REFERENCES

For more information about the ASP transaction service, see the following MSDN article:
http://www.microsoft.com/windows/windows2000/en/datacenter/iis/htm/asp/asps4pim.asp?DontFrame=1 (http://www.microsoft.com/windows/windows2000/en/datacenter/iis/htm/asp/asps4pim.asp?DontFrame=1)

APPLIES TO
  • Microsoft Active Server Pages 4.0
Keywords: 
kbhowto kbhowtomaster kbtransaction KB299637
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate