In my .net 4 solution, i have two different projects- an web application project and a class library project.
In web application project, database connection string
To access it from your class library add a reference to System.Configuration
then use System.Confinguration.ConfigurationManager.ConnectionStrings
.
It's not ideal to read this from a class library. After all, can you say that your class library will always be consumed by something with a configuration file? Certainly not if you share it with other developers, especially of different platforms.
Consider:
e.g.:
public class MyLibraryContainer
{
private string _connectionString;
public MyLibraryContainer(string connectionString)
{
_connectionString = connectionString;
}
}