Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    connecting to their DB

    Good day,

    here the situtation:
    -I have the clients asp pages that links to their database.
    -They gave me a copy of their DB as an Access file

    --Now I need to run a couple of queries to check my pages from my server, how do I connect to my DB without rewriting their code(or change it as little as possible) because after the client aproves the page they put it back on their server, with the old path to connect to their DB

    <object id="objCONN" Progid="ADODB.Connection" Runat="server">
    </object>
    <object id="rs1" Progid="ADODB.Recordset" Runat="server">
    </object>
    <object id="objRS2" Progid="ADODB.Recordset" Runat="server">
    </object>

    <%Dim sql1

    objCONN.open Application("Products_ConnectionString")
    sql1 = "SELECT i, school, date_start, career_fair FROM recruiting_calendar ORDER BY date_start DESC"
    objRS1.CursorType = 2
    objRS1.LockType=3
    objRS1.source = sql1
    objRS1.ActiveConnection = objCONN
    objRS1.Open
    %>

    ???sorry if this sounds like a newbie question but I am a newbie???
    any help or direction would be great
    thanks
    Ken

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    The best method for this is to store the connection string on another page. Then when you need to use the connection string you would simply use an include file to get it. This way you only have one page to change. on a small site with only a couple pages it isnt a problem to change the connection string on each page but when you work on a large site with hundreds of pages it is a pain to do so on each one. In this example i have named the page dbpath.asp and it will show where the database is located on the server. Which in this instance is a directory named Database inside the inetpub directory but outside of the wwwroot directory
    Code:
    <%
    Dim myConnectionString, dbPath
    dbPath = dbPath = "d:\inetpub\Database\"
    myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbPath & "myAccessDatabase.mdb; Jet OLEDB:Database
    Also I would get rid of the object tags and handle the creation of the objects inside the script delimeters. This way you can clear them from memory when you are done using them.

    use this instead
    Code:
    <!--#include file="dbpath.asp"--> 
    
    <%
    
    dim objConn, sql1, objRs1
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open myConnectionString
    sql1 = "SELECT i, school, date_start, career_fair FROM recruiting_calendar ORDER BY date_start DESC"
    Set objRs1 = Server.CreateObject("ADODB.Recordset")
    objRs1.Open  SQL, objConn, 2, 3
    If Not objRs1.BOF And Not objRs1.EOF Then 
    
    'display your results
    
    End If
    
    'remember to close and release the objects from memory when done using them
    objConn.close
    Set objConn = Nothing
    objRs1.close
    Set objRs1 = Nothing
    %>
    An even more efficient way is to dump the recordset object and just use the connection object's execute method to get your results.


  •  

    Posting Permissions

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