ASP.NET
  Home arrow ASP.NET arrow Page 3 - 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 Cancel Method


    (Page 3 of 15 )

    This method cancels the execution of a pending, asynchronous Execute or Open operation.

    Connection.Cancel

    This is particularly useful when writing applications that allow a user to specify connection details, or when users explicitly log on to a connection. If, after a certain delay, the connection has not been established, you can inform the user and offer the option of canceling the connection attempt. For example, in Visual Basic you could open the connection asynchronously and offer the user a Cancel button, which would call this method.

    The Close Method

    This method closes an open connection and any dependent objects.

    Connection.Close

    Closing a connection does not remove it from memory, and you can change its settings and reopen it. To free the object from memory (assuming no one else is using the object), you must set the object variable to Nothing. For example:

    objConn.Close
    Set objConn = Nothing

    To avoid getting an error when trying to close a connection that is not open, you can check the Connection object’s State property:

    If objConn.State = adStateOpen Then
       objConn.Close
    End If
    Set objConn = Nothing

    When the connection’s Close method is called, associated recordsets and commands behave differently. Any Recordset objects associated with the connection are closed. Any Command objects associated with the connection will persist, but the ActiveConnection parameter will be cleared, thus disassociating the command from any connection.

    When the Close method is called, any pending changes in Recordset objects associated with the connection will be cancelled. If you call the Close method while a transaction is in progress, an error will be generated. This is a run-time error, number 3246, saying that the Connection object cannot be explicitly closed while in a transaction. In comparison, if a Connection object falls out of scope, any incomplete transactions will be rolled back, and in this case no error is generated.

    The CommitTrans Method

    This method saves any pending changes and ends the current transaction.

    Connection.CommitTrans

    All changes made since the previous BeginTrans will be written to the data store. This only affects the most recently opened transaction, and you must resolve lower-level transactions before resolving higher-level ones. So, if you are nesting transactions, you cannot start two transactions and then Commit or Abort the outer transaction without first Committing or Aborting the inner transaction, because they refer to the same connection.

    If the Connection object’s Attributes property is set to adXactCommitRetaining, the provider automatically starts a new transaction after a CommitTrans call.

    See also the BeginTrans method and the RollbackTrans method. 

    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 1 hosted by Hostway