DbFailureKind Enumeration

Assembly: CodeEffects.Rule.Connection.dll
Namespace: CodeEffects.Rule.Connection

Summary

Specifies what kind of database failure an exception represents, as far as retrying and reporting are concerned. A dialect returns it from IDialect.Classify(..).

Syntax

public enum DbFailureKind
{
	// Not a failure the dialect recognizes; not retried
	Other = 0,

	// The database chose the statement as a deadlock victim. Retried once
	Deadlock = 1,

	// The connection was dropped or could not be opened. Retried once
	ConnectionLost = 2,

	// The command or the connection timed out. Not retried
	Timeout = 3,

	// A table or column the statement names is not there. Not retried
	MissingObject = 4
}

Remarks

The libraries call IDialect.Classify(..) of your IDbProvider on every database exception to decide what to do with it. You only meet this enumeration when you implement a dialect; the dialect of the SQL Server provider classifies SQL Server's errors for you.

Member What the libraries do
Other Fail the request. The error is reported with the control number CE19002 when the exception comes from the database, and as an unexpected error otherwise.
Deadlock Run the whole unit of work again, once. The first attempt has already been rolled back. If it fails again, report CE19002.
ConnectionLost Run the unit of work again, once, as for a deadlock.
Timeout Fail the request with CE19003 and the message "The rule storage database did not respond in time. Please try again." The next attempt would likely time out too, so it is not retried.
MissingObject Do not retry. The libraries then read the schema version of the database. When it is behind the library, the request fails with CE19004 and a message that names the update scripts to run, in place of the database's own error. When it is not, the failure is reported as CE19002.

Do not classify a wrong server name or an unreachable server as ConnectionLost. Retrying those only makes the user wait for the connection timeout twice. The SQL Server provider classifies only the failures of a connection that was already established, or that was lost while the database failed over, as ConnectionLost.

Example

using System;
using CodeEffects.Rule.Connection;

IDialect dialect = dbProvider.Dialect;

try
{
	// Run a statement of your own through the same connection provider
}
catch(Exception ex)
{
	if(dialect.Classify(ex) == DbFailureKind.Deadlock)
	{
		// Run it again once, as the libraries do
	}
}

Ask on Stack Overflow - Yes, it's still active
Ask in GitHub Discussions

p102

l097 --

l102

p101

×