Connection String

A

A.M

Hi,

I have an encrypted database connection string stored in web.config file and
i need to have the connection string several times in my application.

What would be the best way to have that connection string in memory variable
?

I am thinking to add a member variable to Global class in global.aspx.cs and
initialize it in Application_Start event handler. Is it the best practice?

Thanks,
Ali
 
M

Marina

I think the important thing, is to have a function you can call to get the
connection string. After that, it doesn't matter, since if one way turns out
too slow, you can just change the code in the function to retrieve the
connection string another way. If you do this, at most you will have to
change one place as far as retrieving the string, since you will always just
be calling that one function.

It will probably be slightly more efficient to load up the string once,
decrypt it, and store the connection string ready to go in memory.
 
S

Stanley

Why do you want it in memory? You can grab it anytime you want from your
web.config. Putting it in memory just means less memory for other things.
Just my opinion here but I like to save the memory for more important
things.

-Stanley
 
M

Marina

The only reason would be to not have to decrypt it every time, since it's
being stored encrypted. Besides, even if it was being stored in plain text,
do you think one string the size of a connection string would take up enough
memory for it to actually make a difference? If the memory performance of
an application is ruined by having a connection string in memory at all
times, then there are real problems...
 
K

Kirk Graves

We do the same thing on any of the ASP.Net applications we work on. the
connection string gets stored in the web.config encrypted, then on
application_start we pull it out, decrypt it, then store it in an
application variable. however, we added one thing, we created a function in
global that checks to make sure the value is still there, reloads if
necessary, then returns the connection string. this way there is not risk
of having the variable die on us for any reason. If it does, it is
automaticly reloaded the next time someone needs it.

kirk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top