Home  /  Questions  /  Question



108   96.7
May 16, 2012


Connectionstring explanations please

What is the purpose of these 2 connection string related lines:

1) is under DataObjects/ADO.NET/SqlServer
private static readonly string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionStringName");
private static readonly string connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

2) the other is in DataObjects

private static readonly string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionStringName");
private static readonly IDaoFactory factory = DaoFactories.GetFactory(connectionStringName);


Thanks
Dennis



578   99.9
Jun 01, 2012
Dennis,

These are all essentially dynamic ways to get the correct connection string from your web.config file.  As you know, you can have more than one connection string configured in your web.config/connectionStrings section. 

By placing a key in the appSettings section for a selected connection string you want to use specifically, you are telling your DataObjects factory which connection string you want to use.  This is a cleaner way of getting the connection string, in my opinion, than hard-coding the connection string name in your factory class, or by identifying it by it's index.

I hope that answers your question.

Thanks,

King Wilder