Re: Proper Database Connection Cleanup



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
    ... Sylvain Lafontaine, ing. ... "The database file has been created by an earlier ... The conn object opened "nicely". ... Dim Conn As ADODB.Connection ...
    (microsoft.public.access.modulesdaovba)
  • Re: Proper Database Connection Cleanup
    ... Public Sub ConnectToDB2(byref XCmd, byref YRS, byRef Conn) ... Public Sub CloseDBCon ... I am new to using their database and I do connect two or three ...
    (microsoft.public.scripting.vbscript)
  • Re: Proper Database Connection Cleanup
    ... but I think two of them have a database query in them. ... Public Sub ConnectToDB2(byref XCmd, byref YRS, byRef Conn) ... Set ObjRS = ObjCmd.Execute ... from DB connections in my code or from something else? ...
    (microsoft.public.scripting.vbscript)
  • Re: ODBC Connection to SQL Server Compact
    ... "The database file has been created by an earlier ... The conn object opened "nicely". ... Dim Conn As ADODB.Connection ... 'Delete All Records from Mobile Database ...
    (microsoft.public.access.modulesdaovba)
  • Re: How to get the data from a huge table efficiently?
    ... only display/ship the results on the client-side. ... // SQL Server 2000 Database ... Connection conn = null; ... CallableStatement qstmt = conn.prepareCall(sql, ...
    (comp.lang.java.databases)

Loading