Link to home
Start Free TrialLog in
Avatar of ullenulle
ullenulleFlag for United States of America

asked on

Issue with global.asa file...

Hi.

I tried saving a global.asa in the root of the webserver folder:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Application_OnStart
    Dim cnnDem, cnnString
    Set cnnDem = Server.CreateObject("ADODB.Connection")
    cnnDem.CommandTimeout = 60
    cnnString = "Driver={SQL Server};Server=servername\SQLEXPRESS;Database=mcd;Uid=username;Pwd=password"
    Application("conString")=cnnString
    Application("cnn")=cnnString
    Call cnnDem.Open(cnnString)
End Sub
</SCRIPT>

Open in new window


Of course I replaced servername, username and password with the real values. But then no page on my website will show up. I just get the Server 500 error. If I move the global.asa away from the root, then the webfiles works again. What am I doing wrong? And how should I handle the global.asa file correctly to have sql server connection available in my web application?

Best regards

Ulrich
SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ullenulle

ASKER

I'm afraid that didn't change anything... I also removed the  Application-line as you suggested.
try look into Event Viewer and see if there's any suspicious errors you can diagnose?
What section of Event Viewer do you suggest I search? So far I can't see anything suspicious.
Ok. I think there is a login error to the sql server.  But I know the credentials are correct. Is the connection string written in a wrong way??
try look for a valid one at:

https://www.connectionstrings.com/sql-server/

see which one you able to connect with...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Kurt.

Thank you for your comment. And why is it better with web.config than global.asa?
normally, we put all settings to web.config, a central location to adjust/modify the settings...
and opening a connection in global.asa and keep it open is just a big NO!
connection should be opened and closed immediately as soon as possible...
after removing connection from global.asa, the only thing remains here is creating connection string, which we can put it into web.config and get rid of this function all together...
I'll be back in a few with a conclusion. I need to solve an issue with connecting to the database via the website at all... I'll open a new question with this. :-)
Ok. I discarded the global.asa approach. Therefore I will close the  question. Thank you all for your responses. :-)
Thank you again.