Application[] storage issue

  • Thread starter Thread starter Curt tabor
  • Start date Start date
C

Curt tabor

Hello,

I am creating a dbConnection for use through out my application and
storing it in an Application variable. I am doing this in the
Application_Start event in the Global.asax file. The first time the app
is run and a page needs this variable, Application["connection"]
returns null. Subsequent calls to the application work fine. This only
happens on the first run. Is there a better way? Is this some sort of
bug?

Thanks

Curt
 
I'd have to see the code to know exactly what is wrong, but I'd
suggest not taking this approach. You don't want to share a connection
among multiple requests - it will eventually break in mysterious ways.

Open a new connection when you need one and close it as soon as you
are done. The runtime will take care of keeping things running
efficiently.
 
Back
Top