Problem with informations in global.asa

Results 1 to 2 of 2

Thread: Problem with informations in global.asa

  1. #1
    Daniel Guest

    Default Problem with informations in global.asa

    Hello everyone.<BR><BR>I&#039m having a small problem with my web server. There are some .asp pages there and they need to connect to a database. I&#039m storing the datasource name in my global.asa file in the Application_OnStart subroutine like this:<BR><BR>Sub Application_OnStart<BR> Application("cnString") = "my_datasource_name"<BR>end sub<BR><BR>When a given page is accessed through a certain path, say "" everything works fine and my asp code that looks something like this:<BR><BR>Set con = Server.CreateObject("ADODB.CONNECTION")<BR>con.ope n Application("cnString")<BR><BR>works fine. When I change my default web site to point to the "testing" directory it stops working, i.e. Application("cnString") returns an empty string. I&#039ve tried restarting my webserver but nothing....<BR><BR>Any ideas how to fix this?

  2. #2
    Join Date
    Dec 1969

    Default RE: Problem with informations in global.asa

    Don&#039t use application variables to store the connection information for a database. The reason this is not working is because the virtual directory your script resides in has its own Global.asa with its own Application instance. Therefore, it is not reading the Application("cnString") in your root Web&#039s global.asa. You can either add the application variable to the virtual directory&#039s global.asa or use include files.<BR><BR>I recommend using include files myself. Create an ASP page, dbConn.asp, and put it in a directory like /include. dbConn.asp can have the following code:<BR><BR>&#060;%<BR>const strConnectionString = "my_datasource_name"<BR>%&#062;<BR><BR>Then, in all of the pages that need to access the database, simply include dbConn.asp:<BR><BR>&#060;!--#include virtual="/include/dbConn.asp"--&#062;<BR><BR>and then when you establish your connection, do:<BR><BR>objConn.Open strConnectionString<BR><BR><BR>Happy Programming!

Posting Permissions

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