SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Connecting/Closing database connections

    I've taken over webdevelopment (intranet) for a company, but I have very little formal asp/sql experience. I've been doing fine just editing/copying/pasting existing code, but I have some questions and I'm not sure where to find the answers.

    Every asp page has an include at the top with the code:
    Code:
    <%
    dim conn
    set conn=server.createobject("ADODB.Connection")
    conn.open "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\fpdb\workor~1.mdb;"
    %>
    Then at the bottom of every page theres an include with:
    Code:
    <%
    if isobject(conn) then
    	conn.close
    	set conn=Nothing
    else
    end if
    %>
    So when I want to make a connection I just do:
    Code:
    <%
    dim gld
    gld=conn.execute("SELECT field FROM table WHERE this='that'")
    %>
    Field: <%=gld("field")%>
    <%set gld=Nothing%>
    But when I look up code on websites it never really looks like mine. Is the way I'm doing it alright? I mean it works but I have no clue if that's how it should be done.

    Also, is it necessary to do <%set var=Nothing%> whenever I'm done with a variable? If I leave it open is that bad? Will the bottom include close them all for me?

    Let me know if this doesn't make much sense. I just wanna make sure I'm not making any huge mistakes here.

  2. #2
    SitePoint Addict
    Join Date
    Sep 2003
    Location
    Kingston
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The connection string should use the more efficient OLE driver.
    PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("your.mdb")
    Make sure you update to MDAC 2.8 from http://www.microsoft.com/data.

    The include at the bottom of the page closes the database connection. This is good.

    gld is a recordset object. Setting it to nothing is also good.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I appreciate the reply. I'll talk to some of the server guys about the upgrade.


Bookmarks

Posting Permissions

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