Where is best place to put DB connection string?

  • Thread starter Thread starter Arvind P Rangan
  • Start date Start date
Most people aim for web.config, but I would at least encrypt the string if
you do that. There are free books on ASP.NET security at
http://msdn.microsoft.com/architecture. Look at the "Patterns and Practices"
section.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Most people use the web.config, but it certain cases I've found it more
secure to just store it as a global variable within your app where it is
compiled.

-Max
 
If you "store it as a global variable" it must be defined (read
"hard-coded") somewhere. I believe "where" was the question.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
public class myvars
public shared strConnection = "blah blah blah happy now?"
end class

imports YourAppName.myvars

strConnection is now a variable you can use anywhere

Be careful what changes this variable as it is shared, and turn off page
errors so it doesn't bomb out and show your connection string to everyone.

-Max
 
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put
it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie
 
Hi, Max,

As Kevin stated, with this technique the string is hard-coded, which in
other words means it is *not* configurable.

Greetings
Martin
 
Back
Top