Click to See Complete Forum and Search --> : Checking for connection


Heist
01-07-2002, 09:11 AM
How can you check if a connection to an Access DB is open in ASP? I know in
PHP it would look something like :
if(! $link) //checks if link doesn't exists
$link = mysql_connect("mysql_host", "mysql_login", "mysql_password"); //connects

This is very useful when you want to include your connection code in a single
file that every other page can use.

AtomicBob
01-08-2002, 12:10 PM
I am not positive, but I don't think you can create a connection in one ASP
file and attempt to use that same connection in another file.

My suggestion, create a file include with the following code.

<%
Const conConnectionString = "<Your connection string or DSN>"
Dim objConn ' Connection Object

Sub subOpenDatabase
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open conConnectionString
End Sub

Sub subCloseDatabase
objConn.Close
Set objConn = Nothing
End Sub
%>

This code can be called from any page that has the include file. It is a
quick and dirty way to create/destroy connection objects.

- AtomicBob

"Heist" <homelesspunk@hotmail.com> wrote:
>
>How can you check if a connection to an Access DB is open in ASP? I know
in
>PHP it would look something like :
>if(! $link) //checks if link doesn't exists
>$link = mysql_connect("mysql_host", "mysql_login", "mysql_password"); //connects
>
>This is very useful when you want to include your connection code in a single
>file that every other page can use.