Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Check if RS and Conn are open
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Check if RS and Conn are open

 Post Reply Post Reply Page  <12
Author
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2005 at 11:28pm
Originally posted by theSCIENTIST theSCIENTIST wrote:

Thanks ljamal, but it is not working, it errors out with the obvious 'Object required' on pages that have the Conn closed


Just use, on error resume next to escape the error. This is the closest you will get to what you are seeking.
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 07 March 2005 at 12:12am
The trick to making that work - besides the error escape - is to make sure you use the same onject name for all connections.

Lead me not into temptation... I know the short cut, follow me.
Back to Top
theSCIENTIST View Drop Down
Senior Member
Senior Member


Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
Post Options Post Options   Thanks (0) Thanks(0)   Quote theSCIENTIST Quote  Post ReplyReply Direct Link To This Post Posted: 08 March 2005 at 7:58pm
Yes, I'm using the same obj name, and also came to the same conclusion as you, thx.
Back to Top
sifra View Drop Down
Newbie
Newbie
Avatar

Joined: 20 March 2005
Location: United States
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote sifra Quote  Post ReplyReply Direct Link To This Post Posted: 21 March 2005 at 12:22am
It is not necessary to use error trapping. Below is code that sets up three connections, and leaves them in various states.  The cleanup code works regardless of whether the connection is closed, open or nothing.
 
I recommend you create a VBScript asp class to host the connection object, in the terminate event, free your objects.
 
<%
' set up three connections and leave them in various states
Dim oConn1
Dim oConn2
Dim oConn3

Dim strSQL
strSQL = "Provider=SQLOLEDB;Server=myserver;User ID=me;Password=mypass;Database=mydb;"

Set oConn1 = Server.CreateObject("ADODB.Connection")
oConn1.Open strSQL

Set oConn2 = Server.CreateObject("ADODB.Connection")
oConn2.Open strSQL

Set oConn3 = Server.CreateObject("ADODB.Connection")
oConn3.Open strSQL

' now close connection 1 and set to nothing
oConn1.Close
Set oConn1 = Nothing

' close connection 2 but dont free memory
oConn2.Close

' leave conneciton 3 active


%>

<html>
<head>
    <title>Connection object detection test</title>
</head>

<body>

<%
' cleanup code for each connection is exactly the same
If Not oConn1 Is Nothing Then
    Response.Write "<p>oConn1 has not been set to nothing"
    If oConn1.State > 0 Then
        Response.Write "<br>oConn1 is still active = " & oConn1.State
        oConn1.Close
    End If
    Set oConn1 = Nothing
Else
    Response.Write "<p>oConn1 has already been freed"
End If

If Not oConn2 Is Nothing Then
    Response.Write "<p>oConn2 has not been set to nothing"
    If oConn2.State > 0 Then
        Response.Write "<br>oConn2 is still active = " & oConn2.State
        oConn2.Close
    End If
    Set oConn2 = Nothing
Else
    Response.Write "<p>oConn2 has already been freed"
End If

If Not oConn3 Is Nothing Then
    Response.Write "<p>oConn3 has not been set to nothing"
    If oConn3.State > 0 Then
        Response.Write "<br>oConn3 is still active" & oConn3.State
        oConn3.Close
    End If
    Set oConn3 = Nothing
Else
    Response.Write "<p>oConn3 has already been freed"
End If
   

%>
</body>
</html>

Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.