I have a .Net 5 application and want to add Ef Core with Postgres support. I want to validate the database connection string coming from IConfiguration
. Based on this question
How to check is connection string valid?
I know that builders inheriting from SqlConnectionStringBuilder
check the connection string in the constructor. So I created a demo code how the validation could look like
bool Validate(IConfiguration options)
{
try
{
string databaseConnectionString = options.GetConnectionString("Database");
_ = new NpgsqlConnectionStringBuilder(databaseConnectionString);
return true;
}
catch (Exception exception)
{
return false;
}
}
I had a look at the NpgsqlConnectionStringBuilder
https://www.npgsql.org/doc/api/Npgsql.NpgsqlConnectionStringBuilder.html
and see that it does not inherit from the SqlConnectionStringBuilder
. It does not provide a method to validate a connection string.
Does someone know if that class performs a connection string validation when constructing the instance?