Is there a class or an interface in c#, that represents database connection settings?
I want to pass the connection settings to a function like:
public DoWorkOnDb(IDbConnectionSettings settings)
{
SqlConnection connection = new SqlConnection(settings.ConnectionString);
...
}
What I do not want to do is:
- pass a connection, because the function should handle the connection on her own
- pass a connectionstring, because then you could pass all types of strings
- pass multiple strings like server, database, user, password, because then I have to build the connection string in the function.
As far as I understand you need SqlConnectionStringBuilder.
Then you need to call ToString() or TryGetValue() methods.