We are using an embedded Firebird V3.0.2 for our MVC5 Project
Problem: When we update the software, we want to find out if a table exists before we create the new table. Therefor we simply make a select on the desired table and if an exception with sql error code -204
occurs, then the table does not exist. But how can I resolve the error code -204
?
Code:
var lFbCommand = new FbCommand();
lFbCommand.Connection = "MyConnectionstring";
lFbCommand.Connection.Open();
// check if table exists by an select query
lFbCommand.CommandText = string.Format("SELECT FIRST 1 * FROM {0}", "MyTableName");
try
{
pFbCommand.ExecuteNonQuery();
}
catch (FirebirdSql.Data.FirebirdClient.FbException e)
{
if(e.? == -204) // -204 seem to be the errorcode for "Table does not exists."
{
// table does not exist.
}
else
{
throw;
}
}
Note: We want to prevent parsing the message text in the exception. We want to get a clear flag for this error (e.g. the error code via any property).