[This is preliminary documentation and is subject to change.]

Namespace:  Firefly.Box.Advanced
Assembly:  Firefly.Box (in Firefly.Box.dll) Version: (


public DatabaseErrorHandler AddDatabaseErrorHandler(
	DatabaseErrorType triggeringError
Visual Basic (Declaration)
Public Function AddDatabaseErrorHandler ( _
	triggeringError As DatabaseErrorType _
) As DatabaseErrorHandler
Visual C++
DatabaseErrorHandler^ AddDatabaseErrorHandler(
	DatabaseErrorType triggeringError


Type: Firefly.Box.Data.DataProvider..::.DatabaseErrorType
The error to monitor

Return Value

A DatabaseErrorHandler that will be invoked when this error ocures


This example demonstrates the usage of DatabaseErrorHandling
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
using System;
using System.Collections.Generic;
using System.Text;
using Firefly.Box.Data.DataProvider;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;

namespace TestFirefly.Box.Documentation
    public class DatabaseErrorHandling
        public void DatabaseErrorHandlingEventSequence()
            var jobs = new Pubs.Jobs();

            var bp = new BusinessProcess()
                From = jobs,
                Activity = Activities.Insert

            string eventSequence = "";
            bp.PreviewDatabaseError += e =>
                eventSequence += "PreviewDatabaseError " + e.ErrorType + "\n";
                e.HandlingStrategy = DatabaseErrorHandlingStrategy.Rollback;
            bp.DatabaseErrorOccurred += e => eventSequence += "DatabaseErrorOccurred " + e.ErrorType + "\n";
            var handler = bp.Handlers.AddDatabaseErrorHandler(DatabaseErrorType.DuplicateIndex);
            handler.Invokes += e => eventSequence += "DatabaseErrorHandler " + e.ErrorType + "\n";
            bp.ForFirstRow(() =>
                jobs.Id.Value = 1;//Duplicate index error, because job with id 1 already exists
            eventSequence.ShouldBe("PreviewDatabaseError DuplicateIndex\n" +
                            "DatabaseErrorHandler DuplicateIndex\n" +
                            "DatabaseErrorOccurred DuplicateIndex\n");


See Also