SQL query in Global.asa file

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.

Answers


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?


Need Your Help

Run a small scale DDoS attack against a Raspberry Pi Server

nginx raspberry-pi ddos

For a networking class, I want to do a presentation and project on DDoS attacks. I have been researching them for a while and am interested in conducting a small scale attack against a victim serve...

Jquery Validate Error on IE8-10

javascript jquery internet-explorer internet-explorer-8 jquery-validate

I have a checkout page in my e-commerce with jquery validate, in firefox/chrome it works correctly but in internet explorer 8 to 10, I receive the following error: