0

So the previous developer added some application variables in Global.asa file but he hard coded those and we found a bug which need to be dynamic. Now is it possible(or correct way) to add a SQl query to fetch the data and setting the application variable in Global.asa file.

We have this in global.asa

Application("Email_Sales") = "SomeEmail_1@comcast.net"

Now we have new sales person and we give her admin rights in our portal and her email is SomeEmail_2@comcast.net. Now i dont want to change the global.asa file every time a sales person change.and thats why i want to write a query in global.asa. For some process this sales person gets email and now its going to old email. Now i can write a query and fetch the new email where the email are going but that will be on so many places.

let me know if its good or not good to write a SQL query in global.asa file.

Thanks.

arpan shah
  • 277
  • 2
  • 18
  • You haven't told us enough about what the website is supposed to do for anyone to be able to answer that. There's no reason why you can't have a sql query as an application variable, it's more usual to have different sql queries on various .asp pages. Do you actually mean a sql query rather than a connection string. Global.asa is a standard place for connection srings – John Feb 07 '14 at 00:09

1 Answers1

1

Actually I find it a good idea to host dynamic application wide variables in the global.asa file to keep the on site maintenance low. (But only if you need them at various occasions across the site, because otherwise you could call the information just in time with a little function.)

Depending on how often you change your values (lifecycle of app?) you could use something like this:

Sub Application_OnStart()
    Set Conn = ...
    Conn.Open ...
    strSql = "SELECT SALESEMAIL  ...."

    Set objRs = ...

    If NOT objRs.Eof Then
        Application("SALESEMAIL") = objRs("SALESEMAIL")
    End If

    objRs.Close
    Set objRs = Nothing

    Conn.Close
    Set Conn = Nothing
End Sub

Further information: When to use Application_Start vs Init in Global.asax?

Community
  • 1
  • 1
John
  • 1,327
  • 1
  • 17
  • 28