Você pode permitir que o
SqlConnectionStringBuilder
construtor verifique:bool isValidConnectionString = true;
try{
var con = new SqlConnectionStringBuilder("ABC");
}catch(Exception)
{
// can be KeyNotFoundException, FormatException, ArgumentException
isValidConnectionString = false;
}
Aqui está uma visão geral dos
ConnectionStringBuilders
para os diferentes provedores de dados:Provider ConnectionStringBuilder
System.Data.SqlClient System.Data.SqlClient.SqlConnectionStringBuilder
System.Data.OleDb System.Data.OleDb.OleDbConnectionStringBuilder
System.Data.Odbc System.Data.Odbc.OdbcConnectionStringBuilder
System.Data.OracleClient System.Data.OracleClient.OracleConnectionStringBuilder