[thelist] best practice question

Chris at globet.com Chris at globet.com
Tue Aug 8 13:56:29 CDT 2006


Casey

> This is not a specific question, but a "what's the most 
> efficient way to..." question.  In dealing with connection 
> strings, the actual string itself is of course in the 
> web.config file.  But, when referring to the connection using: 
> 
> Dim dbConnect As SqlConnection = New
> SqlConnection(ConfigurationSettings.AppSettings("dataConnection"))
> 
> What's the best method to keep from repeating this line in 
> each and every .ascx or .aspx file?  In other words, I'd like 
> dbConnect to be a global object that I don't need to 
> instantiate on every page, and certainly not within every 
> function.  For example, could this line be included in the 
> global.asax file? And if so, in what sub?

I have used a SqlHelper class with (amongst others) a static method
GetConnection(). When I need a connection, in VB I would specify:

Dim dbConnect As SqlConnection = SqlHelper.GetConnection()

I don't know if this is best practice, though.

I like your problems - I've not been using .NET that long so they're
helping me consolidate my knowledge :)

Cheers!

-- 
Chris Marsh
Software Developer
t: +44 20 8246 4804 x828
f: +44 20 8246 4808
e: chris at globet.com
w: http://www.globet.com/

Any opinions expressed in this email are those of the individual and not
necessarily the Company. This message is intended for the use of the
individual or entity to which it is addressed and may contain
information that is confidential and privileged and exempt from
disclosure under applicable law. If the reader of this message is not
the intended recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, please contact the
sender immediately and delete it from your system. 

 



More information about the thelist mailing list