Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2004, 06:29 PM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Command Object -- How to close db connection?

I'm borrowing some dreamweaver scripts in a large application. The end of one insert script reads:

  Set MM_insertCmd = Server.CreateObject("ADODB.Command")
  MM_insertCmd.ActiveConnection = "strConnect"
  MM_insertCmd.CommandText = MM_insertStr
  MM_insertCmd.Execute

As I understand it, this creates a new connection to the db.
If I afterward then do this:

Set MM_insertCmd = nothing

will that not only eliminate the command object from memory, will it also close the db connection? Is it necessary to somehow close the connection first, before setting the command object to nothing? Or will simply setting it to nothing "kill two birds with one stone"?

Thanks for any help.


 
Old July 27th, 2004, 06:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,

Yes, this way of setting to nothing does release the command object from memory. The connection has to be explicitly closed using Close() method of the connection object.

Closing connection is done using,
ObjCONNECTION.Close()

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 28th, 2004, 02:05 PM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply . . .
I'm not still not sure, though, how to close the db connection since I don't have an ObjCONNECTION object. How could I use the close method for an object I don't have? The only thing I have is a command object for which the last method was .execute

Is ObjCONNECTION.Close()a function that I can use, as is, without
defining ObjCONNECTION an object or variable? Is that all that is necessary?

Sorry, I'm just a beginner.
Thanks


Quote:
quote:Originally posted by happygv
 Hi there,

Yes, this way of setting to nothing does release the command object from memory. The connection has to be explicitly closed using Close() method of the connection object.

Closing connection is done using,
ObjCONNECTION.Close()

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 28th, 2004, 08:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Well, if you get no error when you execute the command without opening the connection first, you won't get one when you close it. Ideally, you would do:

objCommand.Connection.Open()
objCommand.ExecuteNonQuery()
objCommand.Connection.Close()
objCommand = Nothing

Brian
 
Old July 31st, 2004, 05:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure if Brian's suggested code would work. I assume that code pertains to ADO.Net and cannot be used for classic ASP. If wolfpack391 is looking for Classic ASP code then ADO command object supports only the following Methods.

Cancel - Cancels an execution of a method
CreateParameter - Creates a new Parameter object
Execute - Executes the query, SQL statement or procedure in the CommandText property

Though it works without having a connection object, for closing the connection explicity later, I would suggest you to use a connection object initially and then a command object, and finally close connection object, if you are looking to do that.

You can take a look at ADO Command Object. Also I would suggest you to take a look at the ADO Objects Hierarchy/Model for better understanding. ADO Object Model

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
command-line to close access?? ihsail BOOK: Access 2003 VBA Programmer's Reference 2 April 4th, 2011 10:52 AM
Command text was not set for the command object Sheraz Khan Classic ASP Databases 2 May 29th, 2007 12:57 AM
Command text was not set for the command object. deepa12 BOOK: Beginning ASP 3.0 5 November 2nd, 2004 05:37 PM
open close db mikeuk PHP Databases 3 July 19th, 2004 11:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.