need code to test if connection open or not
Could someone please help me -- I need some code to test whether my connection is open in an asp page. Something like this:
<?php
IF NOT connection is open THEN
Connection string code here
END IF
?>
I know how to write the connection string, it's the first part of testing whether it's closed or not that I don't know.
Thanks
necrotic posted this at 00:00 — 9th May 2002.
He has: 296 posts
Joined: May 2002
<?php
if (!$connection) {
echo $connection;
}
?>
Is that what you want?
dk01 posted this at 10:10 — 9th May 2002.
He has: 516 posts
Joined: Mar 2002
I think they want ASP code.
You could probly do something like this:
Set Conn = Server.CreateObject("ADODB.Connection")
ConnString = "Provider=MSDASQL;Driver={Microsoft Access Driver (*.mdb)}; "
ConnString = ConnString & "DBQ=" & Server.MapPath("\path\datbase.mdb") & "; "
ConnString = ConnString & "PWD=databasepassword"
Set OpenConn = Conn.Open(ConnString)
If Not OpenConn=0 Then
Response.Write "Database opened"
End If
That code would probably work (may take some tweaking) but the problem is that ASP would give you an error before you even get to check for the connection being open. If you could turn off these errors then you might be able to work out some sort of way to do it.
Good luck.
-dk
necrotic posted this at 00:17 — 10th May 2002.
He has: 296 posts
Joined: May 2002
O, didn't look at the <% tags... o well. I don't know ASP.
Peter J. Boettcher posted this at 12:36 — 10th May 2002.
They have: 812 posts
Joined: Feb 2000
The code I always use is:
If objADOConnection.State Then objADOConnection.Close
Set objADOConnection = Nothing
End If
objADOConnection is my ADO Connection. This If statement detects if the connection is open and closes it if it is.
PJ | Are we there yet?
pjboettcher.com
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.