Can I use database commands in my Global.ASA file?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Can I use database commands in my Global.ASA file?

    Can I use database commands in my Global.ASA file like this...?

    Sub Session_OnStart
    Public adoCon
    Dim recset
    Set adoCon = Server.CreateObject("ADODB.Connection")
    adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
    Server.MapPath("parts.mdb")
    Set recset = Server.CreateObject("ADODB.Recordset")
    End Sub

    I already tried it, but I had problems. However, I read somewhere that it
    could be done. Does anyone have any experience in doing this?

    (My goal is to have the database opened at the start of each of my web pages
    without having to type in the commands.)

    Thanks!!


    michaaal Guest

  2. Similar Questions and Discussions

    1. File system commands
      Hi, I've been trying to work out how to issue file system commands from a PHP script to Redhat Linux. I want to be able to delete files and...
    2. Why do my commands keep disappearing? (file, edit, document, tools, etc.)
      using windows xp, acrobat 5.05 Why do my commands keep disappearing as I do things in Acrobat. First the "file" command will disappear, then the...
    3. Global.asa and DSN-less database connections
      OBJECTIVE: I am trying to create a connection to an access database in and then use that connection ASP pages in my application without having to...
    4. Problem with global.asa database and Session OnEnd
      Agggghhhh.... I've read countless posting and still can't get an answer that works. I'm trying to update a record when a session ends. Here's the...
    5. Can I open a database connection in my GLOBAL.ASA file?
      Can I use my GLOBAL.ASA file to open a database connection before each page loads? Would someone mind posting a very simple example? I tried to...
  3. #2

    Default Re: Can I use database commands in my Global.ASA file?

    > Public adoCon
    > Dim recset
    > Set adoCon = Server.CreateObject("ADODB.Connection")
    > adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
    > Server.MapPath("parts.mdb")
    > Set recset = Server.CreateObject("ADODB.Recordset")
    What are you trying to do? Create a recordset object in a session variable,
    or just execute a SQL command? It is not clear from your code what you are
    trying to do, nor is it clear what "had problems" means...
    > (My goal is to have the database opened at the start of each of my web
    pages
    > without having to type in the commands.)
    No, this is a VERY BAD idea. There are several links here that *should*
    convince you that opening and closing the database in each page makes more
    sense (and really isn't much work having to "type in" commands; use an
    #include!), if you read them with an open mind.

    [url]http://www.aspfaq.com/show.asp?id=2053[/url]


    Foo Man Chew Guest

  4. #3

    Default Re: Can I use database commands in my Global.ASA file?

    michaaal wrote:
    > Can I use database commands in my Global.ASA file like this...?
    >
    > Sub Session_OnStart
    > Public adoCon
    > Dim recset
    > Set adoCon = Server.CreateObject("ADODB.Connection")
    > adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
    > Server.MapPath("parts.mdb")
    Don't use ODBC. Use the native Jet OLEDB provider instead
    ([url]www.able-consulting.com/ado_conn.htm[/url])

    adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _
    Server.MapPath("parts.mdb")

    > Set recset = Server.CreateObject("ADODB.Recordset")
    > End Sub
    >
    > I already tried it, but I had problems.
    What problems? how can we help if you don't tell us the error messages you
    received?

    My guess is that you need to grant Modify permissions for the folder
    containing the database to the IWAM account.
    > However, I read somewhere
    > that it could be done. Does anyone have any experience in doing this?
    >
    > (My goal is to have the database opened at the start of each of my
    > web pages without having to type in the commands.)
    >
    This is a bad goal to have if you want your web server to perform
    efficiently:
    [url]http://www.aspfaq.com/show.asp?id=2053[/url]
    [url]http://www.aspfaq.com/show.asp?id=2424[/url]

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  5. #4

    Default Re: Can I use database commands in my Global.ASA file?

    Just wanted to say thanks, guys. The comments you provided were very
    objective and informative.


    michaaal Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139