I am wondering if there is an elegant way to check for the existence of a DB? In brief, how do test the connection of a db connection string?
Thanks
You could just try connecting to it. If it throws an exception, then the connection string is bad in some way, either the database doesn't exist, the password is wrong, or something else.
DbConnection db = new SqlConnection(connection_string);
try
{
db.Open();
}
catch ( SqlException e )
{
// Cannot connect to database
}