Re: Proper Database Connection Cleanup



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.


.



Relevant Pages

  • Re: ODBC Connection to SQL Server Compact
    ... new records from ADO or if you can't read any record from the database as ... Sylvain Lafontaine, ing. ... Use only 'execute' commands from con objet with no Rs (recordset) used. ... The conn object opened "nicely". ...
    (microsoft.public.access.modulesdaovba)
  • Re: How to import certain fields from access database?
    ... I added the code but its not displaying any values in the textboxes. ... The first imports data from a database ... Dim myActiveRecord As Recordset ...
    (microsoft.public.word.mailmerge.fields)
  • Re: How to import certain fields from access database?
    ... I added the code but its not displaying any values in the textboxes. ... The first imports data from a database ... Dim myActiveRecord As Recordset ...
    (microsoft.public.word.mailmerge.fields)
  • Re: How to import certain fields from access database?
    ... I added the code but its not displaying any values in the textboxes. ... The first imports data from a database ... Dim myActiveRecord As Recordset ...
    (microsoft.public.word.mailmerge.fields)
  • Re: How to import certain fields from access database?
    ... I added the code but its not displaying any values in the textboxes. ... The first imports data from a database ... Dim myActiveRecord As Recordset ...
    (microsoft.public.word.mailmerge.fields)

Loading