Best Practice for using a string across the app??

  • Thread starter Thread starter David Lozzi
  • Start date Start date
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!
 
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!
 
Back
Top