ASP.NET
  Home arrow ASP.NET arrow Page 13 - The Connection Object
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

The Connection Object
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    2004-09-27

    Table of Contents:
  • The Connection Object
  • Connection State
  • The Cancel Method
  • The Execute Method
  • The Open Method
  • The OpenSchema Method
  • Properties of the Connection Object
  • The ConnectionTimeout Property and More
  • The Mode Property and Provider Property
  • The State Property and Version Property
  • Events of the Connection Object
  • The BeginTransComplete Event
  • The Disconnect Event
  • The RollbackTransComplete Event
  • Collections of the Connection Object

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Connection Object - The Disconnect Event


    (Page 13 of 15 )

    This event fires after a connection is closed.

    Disconnect(adStatus, pConnection) 

    Parameter Type Description
    adStatus EventStatusEnum
    (Long)
    Identifies the status of the event
    pConnection Connection The Connection object for which this event applies You can use this to examine whether the disconnection was successful.

    You can also use it to track users as they log on to and off from data sources. It can also be useful to alert users when a connection drops unexpectedly.

    The ExecuteComplete Event

    This event fires after a statement has finished executing.

    ExecuteComplete(RecordsAffected, pError, _
                  adStatus, pCommand, _
                  pRecordset, pConnection)

    Parameter Type Description
    Records AffectedLong A Long variable into which the provider returns the number of records that the operation affected
    pError Error An Error object that describes the error that occurred if adStatus is adStatusErrorsOccurred (not set otherwise)
    adStatus EventStatus
    Enum (Long)
    Identifies the status of the event
    pCommand Command Command object for which this event applies (may not be set if a Command object was not used)
    pRecordset Recordset Recordset object upon which the Execute was run (may be empty if a non-recordset-returning command was run, such as an action query)
    pConnection Connection Connection object upon which the Execute method was called

    This allows you to examine whether the command completed successfully and how many records it affected. You can use this instead of the Execute method’s RecordsAffected argument. The following Visual Basic code shows the use of this event:

    Private Sub objConn_ExecuteComplete( _
            ByVal RecordsAffected As_Long, _
            ByVal pError As ADODB.Error, _
            ByVal adStatus As ADODB.EventStatusEnum, _
            ByVal pCommand As ADODB.Command, _
            ByVal pRecordset As ADODB.Recordset, _
            ByVal pConnection As ADODB.Connection)
    If adStatus = adStatusOK Then
    Print RecordsAffected & _
           " records were affected by this command."
    End If

    End Sub

    The nonhighlighted code is the Visual Basic generated event procedure.

    The InfoMessage Event

    This event fires whenever a connection event operation completes successfully and the provider returns additional information, such as a warning.

    InfoMessage(pError, adStatus, pConnection)

    Parameter Type Description
    pError Error An Error object that describes the error that occurred if adStatus is adStatusErrorsOccurred (not set otherwise)
    adStatus EventStatusEnum
    (Long)
    Identifies the status of the event
    pConnection Connection Connection object upon which the statement was executed

    The parameters define what type of information message this is. This is particularly useful when dealing with ODBC data sources, especially to SQL Server, because it returns informational messages that could be logged in an audit trail.

    For example, you could connect to the pubs database on SQL server with this connect string:

    Driver={SQL Server}; Server=Tigger; Database=pubs; _
                  UID=sa; PWD=

    and then put this code into the InfoMessage event procedure:

    Private Sub oConn_InfoMessage(ByVal pError As _
                  ADODB.Error, _ 
                  adStatus As ADODB.EventStatusEnum, _
                  ByVal pConnection As ADODB.Connection)
       Dim objError As ADODB.Error

       Debug.Print pError.Description

       For Each objError In pConnection.Errors
          Debug.Print vbtab; objError.Description
       Next
    End Sub

    On my server, the above code generates the following warnings when connecting to the pubs database in SQL Server using the OLE DB Provider for ODBC:

    [Microsoft][ODBC SQL Server Driver]
       [SQL Server]Changed database context to 'master'.
    [Microsoft][ODBC SQL Server Driver]
       [SQL Server]Changed database context to 'master'.
    [Microsoft][ODBC SQL Server Driver]
       [SQL Server]Changed language setting to 'us_english'.
    [Microsoft][ODBC SQL Server Driver]
       [SQL Server]Changed database context to 'pubs'.

    In general, this event can be used to track connection messages or actions on the connection that return the ODBC SQL_SUCCESS_WITH_INFO result. 

    This is from ADO Programmer's Reference, by Dave Sussman (Apress, ISBN 1590593421). Check it out at your favorite bookstore today. Buy this book now.

    More ASP.NET Articles
    More By Apress Publishing


     

    ASP.NET ARTICLES

    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway