DbExceptionClassifier.MySQL
1.0.0
dotnet add package DbExceptionClassifier.MySQL --version 1.0.0
NuGet\Install-Package DbExceptionClassifier.MySQL -Version 1.0.0
<PackageReference Include="DbExceptionClassifier.MySQL" Version="1.0.0" />
<PackageVersion Include="DbExceptionClassifier.MySQL" Version="1.0.0" />
<PackageReference Include="DbExceptionClassifier.MySQL" />
paket add DbExceptionClassifier.MySQL --version 1.0.0
#r "nuget: DbExceptionClassifier.MySQL, 1.0.0"
#:package DbExceptionClassifier.MySQL@1.0.0
#addin nuget:?package=DbExceptionClassifier.MySQL&version=1.0.0
#tool nuget:?package=DbExceptionClassifier.MySQL&version=1.0.0
![]()
DbExceptionClassifier
Classify ADO.NET database exceptions by error type. Works with any ADO.NET provider without requiring Entity Framework Core.
Supports PostgreSQL, SQL Server, SQLite, Oracle, MySQL (MySql.Data and MySqlConnector).
What does DbExceptionClassifier do?
When working with ADO.NET, database exceptions are provider-specific. To determine whether an error was caused by a unique constraint violation, a foreign key violation, or a null constraint, you need to inspect the provider-specific exception type and error codes.
DbExceptionClassifier provides a unified IDbExceptionClassifier interface that classifies DbException instances into common error types:
- Unique constraint violation
- Reference (foreign key) constraint violation
- Cannot insert null
- Max length exceeded
- Numeric overflow
- Deadlock
Getting started
Install the package for your database:
dotnet add package DbExceptionClassifier.PostgreSQL
dotnet add package DbExceptionClassifier.SqlServer
dotnet add package DbExceptionClassifier.Sqlite
dotnet add package DbExceptionClassifier.Oracle
dotnet add package DbExceptionClassifier.MySQL
dotnet add package DbExceptionClassifier.MySQL.Pomelo
Usage
Create an instance of the classifier for your database and use it to classify exceptions:
var classifier = new PostgreSQLExceptionClassifier();
try
{
// Execute your ADO.NET command
await command.ExecuteNonQueryAsync();
}
catch (DbException ex) when (classifier.IsUniqueConstraintError(ex))
{
// Handle unique constraint violation
}
catch (DbException ex) when (classifier.IsReferenceConstraintError(ex))
{
// Handle foreign key violation
}
IDbExceptionClassifier interface
public interface IDbExceptionClassifier
{
bool IsUniqueConstraintError(DbException exception);
bool IsReferenceConstraintError(DbException exception);
bool IsCannotInsertNullError(DbException exception);
bool IsMaxLengthExceededError(DbException exception);
bool IsNumericOverflowError(DbException exception);
bool IsDeadlockError(DbException exception);
}
CompositeExceptionClassifier
If your application connects to multiple database types, use CompositeExceptionClassifier to combine multiple classifiers into one. It delegates to each classifier and returns true if any of them matches:
var classifier = new CompositeExceptionClassifier(
new PostgreSQLExceptionClassifier(),
new SqlServerExceptionClassifier()
);
try
{
await command.ExecuteNonQueryAsync();
}
catch (DbException ex) when (classifier.IsUniqueConstraintError(ex))
{
// Works regardless of which database threw the exception
}
If you want to use another native SQLite binary instead of e_sqlite3.dll use the DbExceptionClassifier.Sqlite.Core package. This package depends on Microsoft.Data.Sqlite.Core, which doesn't include the native SQLite binary so you can use any native binary you want.
Entity Framework Core
If you are using Entity Framework Core, use the EntityFrameworkCore.Exceptions packages instead. They build on top of DbExceptionClassifier and provide typed exceptions that inherit from DbUpdateException.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DbExceptionClassifier.Common (>= 1.0.0)
- MySql.Data (>= 9.6.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DbExceptionClassifier.MySQL:
| Package | Downloads |
|---|---|
|
EntityFrameworkCore.Exceptions.MySQL
Handle database errors easily when working with Entity Framework Core. Catch specific exceptions such as UniqueConstraintException, CannotInsertNullException, MaxLengthExceededException, NumericOverflowException, ReferenceConstraintException or DeadlockException instead of generic DbUpdateException |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 42 | 3/19/2026 |
Initial release