I have a stored procedure that I am calling using the ObjectContext
ExecuteStoreQuery
method so that I can get the result set that the stored procedure returns.
I have it inside of a try/catch block, however even though the stored procedure returns the following error it doesn't fall into the catch block.
How do I trap for this type of error?
Or is there another way of executing a stored procedure and getting a result set back?
Error when executed in SQL:
Msg 50000, Level 16, State 2, Procedure ComputeCharges, Line 6440
The following error occurred while computing charges:
Error Number: 515, Line Number: 5867
Error Message: Cannot insert the value NULL into column 'TransactionAmount', table 'Transactions'; column does not allow nulls. INSERT fails.
Calling code:
using (DbContext dbContext = GetDbContext())
{
using (ObjectContext objContext = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)dbContext).ObjectContext)
{
try
{
IEnumerable<ResultSet> results = objContext.ExecuteStoreQuery<ResultSet>(sqlString).ToList();
}
catch (Exception e)
{
EventLogger.LogException(e, title: "An error occurred while computing charges.", silent: false);
}
}
}