Re: Proper Database Connection Cleanup
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 8 Apr 2007 07:55:06 -0500
When I am done with a recordset I use the Close method. I can reuse the
object by assigning another query and then use Open again. When the program
is done, I use the Close method of the Recordset and Connection objects.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"Bill James" <wgjames@xxxxxxxx> wrote in message
news:eqrDJsaeHHA.4564@xxxxxxxxxxxxxxxxxxxxxxx
Two suggestions to add to your cleanup.
Set ObjCmd.ActiveConnection = Nothing
ObjRS.Close
Also, your statement, "This code will be used over and over", makes me
wonder if you are using the same recordset variable multiple times in the
same page.
--
Bill James
"Jonathan" <Jonathan@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:590224D5-3D64-4C70-AD3A-51335E1357DB@xxxxxxxxxxxxxxxx
I am running IIS with classic ASP and I am having issues loading some of my
pages. I get an error that says:
"The requested resource is in use. "
What I want to do is have a function to open the database in an include
file. This code will be used over and over so it needs to be in one spot.
Here is the code that I am using in an include file named DB.inc:
Public Sub ConnectToDB2(byref XCmd, byref YRS, byRef Conn)
'this function connects to the database
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Mode = 3
Conn.Open ("DRIVER={MySQL ODBC 3.51
Driver};SERVER=localhost;DATABASE=DB;USER=admin;PASSWORD=blahblahblah;OPTION=3;")
Set XCmd= Server.CreateObject("ADODB.Command")
XCmd.ActiveConnection = Conn
Set YRS = Server.CreateObject ("ADODB.Recordset")
end Sub
In my pages, I open the database by calling ConnectToDB2 ObjCmd, ObjRS,
ObjCon At the end of the page, I clean everything up like this:
Set ObjRS = Nothing
Set ObjCmd = Nothing
ObjCon.Close
Set ObjCon = Nothing
Any ideas why I keep getting the resource in use errors? I have several
include files but the database in opened in my page. The page includes the
inc files that manipulate the data from the DB. To have only one DB
connection object, I open the DB only once in my page and clean it up at
the
end.
Thanks for any ideas.
.
- Follow-Ups:
- Re: Proper Database Connection Cleanup
- From: Jonathan
- Re: Proper Database Connection Cleanup
- References:
- Re: Proper Database Connection Cleanup
- From: Bill James
- Re: Proper Database Connection Cleanup
- Prev by Date: Re: Proper Database Connection Cleanup
- Next by Date: Re: internet not show vbscript source code
- Previous by thread: Re: Proper Database Connection Cleanup
- Next by thread: Re: Proper Database Connection Cleanup
- Index(es):
Relevant Pages
|
Loading