Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



ADO Connection Object Close Method

Closes an open object and any dependent objects.

Close Method Syntax (ADO Connection Object)
object.Close
Close Method Remarks (ADO Connection Object)

Use the Close method to close a Connection object to free any associated system resources. Closing an object does not remove it from memory; you may change its property settings and open it again later. To completely eliminate an object from memory, set the object variable to Nothing.

Using the Close method to close a Connection object also closes any active Recordset objects associated with the connection. An ADO Command Object associated with the Connection object you are closing will persist, but it will no longer be associated with a Connection object; that is, its ActiveConnection property will be set to Nothing. Also, the Command object's ADO Parameters Collection will be cleared of any provider-defined parameters.

You can later call the ADO Connection Object Open Method to reestablish the connection to the same or another data source. While the Connection object is closed, calling any methods that require an open connection to the data source generates an error.

Closing a Connection object while there are open ADO Recordset Object objects on the connection rolls back any pending changes in all of the Recordset objects. Explicitly closing a Connection object (calling the Close method) while a transaction is in progress generates an error. If a Connection object falls out of scope while a transaction is in progress, ADO automatically rolls back the transaction.

Close Method Examples (ADO Connection Object)

This VBScript example uses the Open and Close methods on both Recordset and Connection objects that have been opened.

<!-- #Include file="ADOVBS.INC" --> 
<HTML><HEAD> 
<TITLE>ADO 1.5 Open Method</TITLE> 
</HEAD><BODY> 
<FONT FACE="MS SANS SERIF" SIZE=2> 
<Center><H3>ADO Open Method</H3> 
<TABLE WIDTH=600 BORDER=0> 
<TD VALIGN=TOP ALIGN=LEFT COLSPAN=3><FONT SIZE=2> 
<!--- ADO Connection used to create 2 recordsets--> 
<% 
Set OBJdbConnection = Server.CreateObject("ADODB.Connection") 
OBJdbConnection.Open "AdvWorks" 
SQLQuery = "SELECT * FROM Customers" 
'First Recordset RSCustomerList 
Set RSCustomerList = OBJdbConnection.Execute(SQLQuery) 
'Second Recordset RsProductist 
Set RsProductList = Server.CreateObject("ADODB.Recordset") 
RsProductList.CursorType = adOpenDynamic 
RsProductList.LockType = adLockOptimistic 
RsProductList.Open "Products", OBJdbConnection 
%> 
<TABLE COLSPAN=8 CELLPADDING=5 BORDER=0>
<!-- BEGIN column header row for Customer Table--> 
<TR><TD ALIGN=CENTER BGCOLOR="#008080"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Company Name</FONT></TD> 
<TD ALIGN=CENTER BGCOLOR="#008080"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Contact Name</FONT></TD> 
<TD ALIGN=CENTER WIDTH=150 BGCOLOR="#008080"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>E-mail address</FONT></TD> 
<TD ALIGN=CENTER BGCOLOR="#008080"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>City</FONT></TD> 
<TD ALIGN=CENTER BGCOLOR="#008080"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>State/Province</FONT></TD></TR>
<!--Display ADO Data from Customer Table--> 
<% Do While Not RScustomerList.EOF %> 
<TR><TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RSCustomerList("CompanyName")%> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RScustomerList("ContactLastName") & ", " %> 
<%= RScustomerList("ContactFirstName") %> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RScustomerList("ContactLastName")%> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RScustomerList("City")%> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RScustomerList("StateOrProvince")%> 
</FONT></TD></TR> 
<!-Next Row = Record Loop and add to html table--> 
<% 
RScustomerList.MoveNext 
Loop 
RScustomerList.Close 
OBJdbConnection.Close 
%> 
</TABLE> 
<HR> 
<TABLE COLSPAN=8 CELLPADDING=5 BORDER=0> 
<!-- BEGIN column header row for Product List Table--> 
<TR><TD ALIGN=CENTER BGCOLOR="#800000"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Product Type</FONT></TD> 
<TD ALIGN=CENTER BGCOLOR="#800000"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Product Name</FONT></TD> 
<TD ALIGN=CENTER WIDTH=350 BGCOLOR="#800000"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Product Description</FONT></TD> 
<TD ALIGN=CENTER BGCOLOR="#800000"> 
<FONT STYLE="ARIAL NARROW" COLOR="#ffffff" SIZE=1>Unit Price</FONT></TD></TR> 
<!-- Display ADO Data Product List--> 
<% Do While Not RsProductList.EOF %> 
<TR> <TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RsProductList("ProductType")%> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RsProductList("ProductName")%> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RsProductList("ProductDescription")%> 
</FONT></TD> 
<TD BGCOLOR="f7efde" ALIGN=CENTER> 
<FONT STYLE="ARIAL NARROW" SIZE=1> 
<%= RsProductList("UnitPrice")%> 
</FONT></TD> 
<!-- Next Row = Record --> 
<% 
RsProductList.MoveNext 
Loop 
'Remove Objects from Memory Freeing 
Set RsProductList = Nothing 
Set OBJdbConnection = Nothing 
%> 
</TABLE></FONT></Center></BODY></HTML>


ContentsPreviousNextIndex