Checking for connection


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Checking for connection

  1. #1
    Heist Guest

    Checking for connection


    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.

  2. #2
    AtomicBob Guest

    Re: Checking for connection


    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.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center