Is there an way using ADO.NET to determine if a table exists in a database that works with any data provider?
I'm currently doing something like this:
bool DoesTableExist(string tableName)
{
DbCommand command = this.dbConnection.CreateCommand();
command.CommandText = "SELECT 1 FROM " + tableName;
try
{
using (DbDataReader reader = command.ExecuteReader())
{
return true;
}
}
catch (DbException)
{
return false;
}
}
I'm hoping that there is a way that doesn't involve catching exceptions.