Forum Moderators: open

Message Too Old, No Replies

database connection closing problem

         

lindajames

2:42 am on Oct 18, 2004 (gmt 0)

10+ Year Member



i have a database driven page that uses MS Access database. however sometimes when too many connections are opened i cannot access the page and get a unspecified error because all the connections havent been closed.

can anyone can please tell me if there is anyway or anyscript that will close every connection to a database everytime the script is launched? at least this way i can schedule all connections to be closed on the server.

any advice would be very much appreciated.

thanks in advanced.

macrost

2:49 am on Oct 18, 2004 (gmt 0)

10+ Year Member



Well, one thing that you can do is to create a page that has the commands to close the connections and/or recordsets.
Then in every page that uses the db, just include that file and it will be closed.

lindajames

4:20 am on Oct 18, 2004 (gmt 0)

10+ Year Member



sorry i am a complete novice, how can what you suggested be done?

defanjos

4:35 am on Oct 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For example, create a file called closer.asp, and place the following code in it:

<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>

then, at the bottom of the pages that have a recordset and a connection, include this:

<!--#include file="closer.asp" -->

The above assumes your recordset is "rs" and your connection is "conn"

raywood

2:18 pm on Oct 18, 2004 (gmt 0)

10+ Year Member



defanjos has a great idea. The only thing I can add is that if you redirect the server before the script reaches the bottom of the page, you should include these lines before the redirect.
You should always close all your record sets and connections as soon as you're are finished using them.
Including the file at the bottom of all pages is a good way to make sure you don't forget.
You should also destroy all other objects created on a page when you no longer need them.

Easy_Coder

4:39 pm on Oct 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No need to close the connection if it's already closed...

If conn.State = adStateOpen Then
conn.close
End If