Global.asa good practice?

Discussion in 'ASP General' started by Andyza, Aug 25, 2005.

  1. Andyza

    Andyza Guest

    In my Global.asa file I have the following 2 subs for opening and
    closing my db connection:

    Sub OpenConn()
    Dim conn
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open Application("ConnString")
    End Sub

    Sub CloseConn()
    conn.Close
    Set conn = nothing
    End Sub

    Then in my asp pages I simply call the subs when I need to open and
    close the db connection.

    Eg.:

    Dim Test
    Test = "Select XXX from SomeTable"
    OpenConn()
    Set rs = conn.Execute(Test)
    Do While Not rs.eof
    Response.Write(rs("XXX"))
    rs.MoveNext()
    Loop
    CloseConn()

    Is this good practice to have the 2 db subs in the Global.asa?
     
    Andyza, Aug 25, 2005
    #1
    1. Advertising

  2. Andyza

    Andyza Guest

    Ok, bad idea! I wasn't thinking! It won't work - the subs will be out
    of scope in the Global.asa...
     
    Andyza, Aug 25, 2005
    #2
    1. Advertising

  3. Andyza wrote:
    > Ok, bad idea! I wasn't thinking! It won't work - the subs will be out
    > of scope in the Global.asa...


    Not only that, but read this:
    http://www.aspfaq.com/show.asp?id=2053

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Aug 25, 2005
    #3
  4. Andyza

    Aidy Guest

    As you have found out, that doesn't work, but you can put those pages in a
    separate file and INCLUDE them in each ASP page you need them.

    "Andyza" <> wrote in message
    news:...
    > In my Global.asa file I have the following 2 subs for opening and
    > closing my db connection:
    >
    > Sub OpenConn()
    > Dim conn
    > Set conn = Server.CreateObject("ADODB.Connection")
    > conn.Open Application("ConnString")
    > End Sub
    >
    > Sub CloseConn()
    > conn.Close
    > Set conn = nothing
    > End Sub
    >
    > Then in my asp pages I simply call the subs when I need to open and
    > close the db connection.
    >
    > Eg.:
    >
    > Dim Test
    > Test = "Select XXX from SomeTable"
    > OpenConn()
    > Set rs = conn.Execute(Test)
    > Do While Not rs.eof
    > Response.Write(rs("XXX"))
    > rs.MoveNext()
    > Loop
    > CloseConn()
    >
    > Is this good practice to have the 2 db subs in the Global.asa?
    >
     
    Aidy, Aug 25, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darlene Gauthier

    PostRequestHandlerExecute event in global.asa

    Darlene Gauthier, Jul 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,449
    Karl Seguin
    Jul 23, 2003
  2. Kevin Spencer

    Re: global.asa file (count sessions)

    Kevin Spencer, Jul 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    368
    Kevin Spencer
    Jul 30, 2003
  3. Wayne
    Replies:
    2
    Views:
    499
    Wayne
    Nov 11, 2003
  4. vlsidesign
    Replies:
    26
    Views:
    1,040
    Keith Thompson
    Jan 2, 2007
  5. SM
    Replies:
    9
    Views:
    529
Loading...

Share This Page