It is best to catch this catch exception in C # code.
catch(SqlException ex) { if (ex.Message.Contains("UniqueConstraint")) throw new UniqueConstraintException(); throw; }
You can create your own exception and throw it from your data level, otherwise you can directly catch the exception as described above.
using System; public class UniqueConstraintException : Exception { }
Maddy source share