PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Connection string is class module

 
 
Peter Afonin
Guest
Posts: n/a
 
      3rd May 2006
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,

--
Peter Afonin


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      3rd May 2006
> 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


 
Reply With Quote
 
 
 
 
Peter
Guest
Posts: n/a
 
      3rd May 2006
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


 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      3rd May 2006
I've just found another solution - if I use module rather than non-web
class, everything works fine.

Thanks again,

Peter

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection string is class module Peter Afonin Microsoft ASP .NET 3 3rd May 2006 05:53 PM
Difference between Form's Class Module and Class Module tobesurveyor via AccessMonster.com Microsoft Access VBA Modules 4 14th Apr 2006 01:08 PM
Class in a module or class in a class? cj Microsoft VB .NET 4 3rd Mar 2006 11:29 PM
Using Connection Class VS Connection Module Dave Johnson Microsoft ASP .NET 5 11th Dec 2005 02:28 PM
Using Connection Class VS Connection Module in Asp.net Application Dave Johnson Microsoft ADO .NET 4 10th Dec 2005 01:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:02 PM.