473,378 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Connection string is class module

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.AppSetting s("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.AppSetting s("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
May 3 '06 #1
3 1964
> 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.AppSetting s("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.AppSetting s("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
May 3 '06 #2
Thank you very much, Hans.

This:

Dim sCn As String =
System.Web.HttpContext.Current.Application.Item("C onnectionString")
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.AppSetting s("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.AppSetting s("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


May 3 '06 #3
I've just found another solution - if I use module rather than non-web
class, everything works fine.

Thanks again,

Peter

May 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob | last post by:
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem...
1
by: Sean Nolan | last post by:
We have implemented unhandled error trapping at the application level and log these errors to our database. One error, however, the does not get trapped is when the connection pool has exceeded the...
0
by: Bob | last post by:
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem...
5
by: Dave Johnson | last post by:
Working on Asp.net with access database backend,a serious Question in the Class design phase, for accessing the database; Which is Better to make a Connection Class that handles all the ADO...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.