I have a strange situation. I have an existing stored procedure that returns a data back, everything works fine until sql exception occured. When SQL exception occured and this even handled by begin catch
, but Dapper for some reason throws an exception Sequence contains no elements
. Then I replaced QuerySingleAsync<T>
to QueryAsync
to be able to see the sql result itself. It helped to mute the exception (that was generated by Dapper mapper), but result
came back empty. I can’t understand why Dapper doing this way.
SQL
ALTER PROCEDURE [dbo].[MyFavSP]
@SomeName VARCHAR(60),
@SomeValue BIGINT
AS
BEGIN
DECLARE @errMessage VARCHAR(256)
DECLARE @sqlErrCode INT = 0;
BEGIN TRY
select * from MyTable
WHERE 1/0 = 25
set @sqlErrCode = 111
set @errMessage = 'good'
END TRY
BEGIN CATCH
set @sqlErrCode = 999
set @errMessage = 'bad'
END CATCH
SELECT @sqlErrCode ErrorCode, @errMessage ErrorMessage
END
C#
var result = await connection.QuerySingleAsync<MyResult>("dbo.MyFavSP",
new {SomeName = "MyName", SomeValue = 123},
commandType: CommandType.StoredProcedure);