Thank you very much, Hans.
This:
Dim sCn As String =
System.Web.HttpContext.Current.Application.Item("ConnectionString")
cn = New OracleConnection(sCn)
worked great for me.
Peter
Hans Kesting wrote:
> > Hello,
> >
> > I put the connection string to the Web.config file, then in Global.asax I'm
> > assigning this string to the application variable:
> >
> > cn = New OracleConnection
> > cn.ConnectionString =
> > AppCrypto.decrypt(ConfigurationSettings.AppSettings("ConnectionString"))
> >
> > Then I use this to variable to connect to the server:
> >
> > cn = New OracleConnection(Application("ConnectionString"))
> >
> > Everything works great with the webforms. However, to keep my connection
> > code in one place, I put all my connection code in the class module. But in
> > the class module this doesn't work! I have to use exactly the same code as
> > in the Global.asax:
> >
> > cn = New OracleConnection
> > cn.ConnectionString =
> > AppCrypto.decrypt(ConfigurationSettings.AppSettings("ConnectionString"))
> >
> > This is not acceptable, because the connection is encripted, and if it gets
> > decripted every time my application connects to the database, it slows
> > things down badly.
> >
> > Why the application variable doesn't work in the class module? Probably I'm
> > doing something incorrectly. The only solution I see now is to drop my
> > connection class and connect to db in the webforms, which is not a smart
> > application design.
> >
> > Is there a better solution? I would appreciate your advice very much.
> >
> > Thank you,
>
> From a non-web class you can get to Application (and Request, Response,
> Session, ..) with System.Web.HttpContext.Current.Application
>
> (but this only works if there really *is* an HttpContext, it will not
> work from timer-initiated code for instance)
>
> Hans Kesting
|