Best Practice for using a string across the app??

D

David Lozzi

I need to have a string available per page, i.e. the SQL Connection String. What's the best way of doing this? Right now I have it loaded into a session variable, but I think I should do something with global.asax??

Thanks!
 
K

Karl Seguin

the best thing to do is to put it in your web.config. It can then be accessed via ConfigurationSettings.AppSettings("connectionString"). Even better would be to build a wrapper utility for this:

Public NotInheritable Class DatabaseUtility
Private Sub New()
End Sub

Public Shared ReadOnly Property ConnectionString() As String
Get
Return ConfigurationSettings.AppSettings("connectionString")
End Get
End Property

End Class



it can then be accessed via DatabaseUtility.ConnectionString

Session is a bad place for it..since htere'a session by user, but this is a global thing.

--
MY ASP.Net tutorials
http://www.openmymind.net/


I need to have a string available per page, i.e. the SQL Connection String. What's the best way of doing this? Right now I have it loaded into a session variable, but I think I should do something with global.asax??

Thanks!
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top