Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    USA
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple Database Connections

    Is it possible for one ASP page to open connections to two different Access databases at the same time?

    I need to update similar data in two different databases from the same data entry form.

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Database Connections

    Yes - you can easily do this. You can either create a second connection object, or simply declare the database location in the second recordset's parameters.<pre><%
    Set cnn = Server.CreateObject("ADODB.Connection")
    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & Server.MapPath("db/Database1.mdb") & ";"

    Set rst1 = Server.CreateObject("ADODB.Recordset")
    rst1.Open "SELECT * FROM tbl_Customers", cnn, adOpenForwardOnly, adLockReadOnly


    Set rst2 = Server.CreateObject("ADODB.Recordset")
    rst2.Open "SELECT * FROM tbl_Orders", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
    & Server.MapPath("db/Database2.mdb") & ";", adOpenDynamic, adLockOptimistic

    '...

    rst2.Close
    set rst2 = Nothing

    rst1.Close
    Set rst1 = Nothing
    cnn.Close
    set cnn = Nothing
    %></pre>

    Recordset 1 uses the first method (with the Connection object) and Recordset 2 uses the second method (no connection object) - you can mix and match as you like. Of course, Server overhead is probably lower with fewer objects... <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    HTH

  3. #3
    2 Star Lounger
    Join Date
    Aug 2001
    Location
    USA
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Multiple Database Connections

    Thanks.

    Since this situation will not occur on a regular basis, I went with creating two connections.

    It worked perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •