ConnectionException Class
Assembly: CodeEffects.Rule.Connection.dll
Namespace: CodeEffects.Rule.Connection
Summary
Represents a failure of a statement that a Code Effects library ran against rule storage. Its message says in plain words what was being done and is safe to show. The database's own error is the inner exception.
Syntax
public class ConnectionException : CodeEffects.Rule.Common.RuleException
Inheritance
The libraries throw this exception when a statement against the database fails, for example "Could not read the repository's settings." Log the exception, including its InnerException, on the server. The inner exception holds the error of your database, which can name tables, columns, and servers: keep it out of anything a browser receives. The Message and the ControlNumber inherited from RuleException are safe to show.
Where you see it depends on the call. Methods that return a result directly, such as Context.GetAliasNames(..), Context.GetRules(..), and AuditRecorder.GetRules(..), can throw it. A connection that cannot be opened reaches you as the exception of your ADO.NET provider, because the libraries open it outside the statement. Context.GetResponse(..) catches every failure and throws a RepositoryException instead, whose control number and safe message come from the same classification, and whose ResponseJson you can return to the client. Context.SyncSources(..) reports a failed definition in its SourceResult and then throws a RepositoryException.
The control number tells the cause apart:
| Control number |
Constant |
Cause |
CE19002 |
DatabaseError |
A database error that is not a timeout. This is the default. |
CE19003 |
DatabaseTimeout |
The database did not respond in time. |
CE19004 |
SchemaBehind |
A table or column is missing because the database is behind the library. The message names the update scripts to run. See SchemaCheckResult. |
The classification of an error as a timeout or as a missing object comes from the IDialect of your provider through Classify(..), which returns a DbFailureKind.
Constructors
ConnectionException(string, Exception)
Initializes a new instance of the ConnectionException class with the control number DatabaseError (CE19002), the specified message, and the exception that caused it.
Parameters
- message (
System.String) - The message that says what was being done, in words that are safe to show.
- innerException (
System.Exception) - The exception of the database. It becomes the value of the InnerException property.
ConnectionException(string, string, Exception)
Initializes a new instance of the ConnectionException class with the specified control number, message, and the exception that caused it.
Parameters
- number (
System.String) - The support control number of the exception. It becomes the value of the ControlNumber property. Use one of the constants of this class.
- message (
System.String) - The message that says what was being done, in words that are safe to show.
- innerException (
System.Exception) - The exception of the database. It becomes the value of the InnerException property.
Fields
DatabaseError
Type: System.String (constant, value "CE19002")
The control number of every failure of rule storage that is not a timeout and not a schema that is behind.
DatabaseTimeout
Type: System.String (constant, value "CE19003")
The control number of a failure of rule storage that a timeout caused.
SchemaBehind
Type: System.String (constant, value "CE19004")
The control number of a failure on a table or column that is not there, in a database whose schema is behind the library. The message says which update scripts to run.
Properties
Example
using System;
using CodeEffects.Rule.Connection;
using CodeEffects.Rule.Repository;
try
{
var aliases = Context.GetAliasNames(dbProvider);
}
catch(ConnectionException ex) when(ex.ControlNumber == ConnectionException.SchemaBehind)
{
// Safe to show: it names the update scripts to run
Console.WriteLine(ex.Message);
}
catch(ConnectionException ex)
{
// Log the database's own error on the server only
Console.WriteLine($"{ex.ControlNumber}: {ex.Message}");
Console.WriteLine(ex.InnerException);
}