Hi I hope someone can help me. I'm writing a asp system and I'm using mostly classes for my rules, etc... But I would like to know if there is a better way to "declare" my connection string. Typing it out in every class for every "Action" can be a bit messy later on if I want to change my connection string.
Classic ASP? .NET? Just have an include or have a class that gets inherited by all classes like Config class. Or have it in the Web.Config and get it by ConfigurationManager.AppSettings("ConnStr") or keep it in a registry setting or well.. you get the picture
Thank you all for the replies I'm using .NET. What I've done is, I've made a connection class and in each class just calls the connection class... So far it's working good I want too know if you all think what I've done is the correct way?
Well it is only a matter of taste. For example what i am doing for some of my applications is also creating a class connector ... like following Imports System.Data.SqlClient Public Class Connector Public Shared Function GetConnection() As SqlConnection Dim connectionString As String _ = "Server=.\SQLExpress;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" Return New SqlConnection(connectionString) End Function End Class Code (markup): Then you can use the shared func wherever you need ... as it follows: Dim connection As SqlConnection = Connector.GetConnection() Code (markup): HTH Regards
Normally would put it in the web.config file as an application setting as these sit constantly in the system memory and saves calling a function every time you want to use it