Try this try and cath. put your SaveChanges() method inside the try block. try { db.tbl_Payroll_full_day_leaves.Add(tbl_Payroll_Leaves); if (0 < db.SaveChanges()) { return true; } else { return false; } } catch (DbEntityValidationException e) ...