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?
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...
}