In my old project with .Net Framework use from
using System.Data.SqlClient;
and
if (ex.GetType() == typeof(SqlException))
{
return ErrorMessage((SqlException)ex);
}
and now in .NET CORE Does not know Code above
How to use typeof(SqlException)
in .NET CORE?
This is a wrapper for the Number property of the first SqlError in the Errors property. If Errors is null , the default value for int is returned. For more information on SQL Server engine errors, see Database Engine Events and Errors.
Property ValueA value from 1 to 25 that indicates the severity level of the error.
The System. Data. SqlClient. SqlException is typically thrown when an accessed SQL Server returns a warning or error of its own.
In .Net Core version, you need to install this package before using it: Microsoft.EntityFrameworkCore.SqlServer
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.1.4
try
{
// code goes here...
}
catch (SqlException sqlEx)
{
// code goes here...
}
catch (Exception ex)
{
// other exception...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With