Dapper does not catch error when I try and insert a duplicate record. It however populates the first record of the result with the error message. E.g.
try
{
var result = Dapper.SqlMapper.Query(SCADConn, sql, d, null, true, 30, ct);
return result;
}
catch (Exception e)
{
throw (e);
}
When I run the above code the result variable contains a record with a count of 1 row with the following DapperRow
{{DapperRow, ErrorNumber = '2601', ErrorSeverity = '14', ErrorState = '1', ErrorProcedure = 'OrganizationAdd', ErrorLine = '55', ErrorMessage = 'Cannot insert duplicate key row in object 'dbo.Organization' with unique index 'IX_Organization_1'. The duplicate key value is (AAA Purchasing Pty (Ltd), 123123123123).'}}
What a stupid mistake. I returned a record with the error in stored proc error handling.