0

I'm writing one update statement in my procedure but there are chances that CommandTimeout(30 sec for testing my code) may expire. So I was looking for a solution.

Then I came to know that in mysql Diagnostic is available. So i tried that. It is working fine in my workbench. It is returning the variable with message that after which count it is failing.

To execute the procedure failure I putted a condition that if it is true then say signal error

I'm executing this line of code in c#

object Result = _DBCommand.ExecuteScalar();

And after this when timeout is happening mysql error in coming.

I'm wondering how can i catch the variable that I'm throwing from Procedure.

DROP PROCEDURE IF EXISTS udsp_Test;
DELIMITER //

CREATE PROCEDURE udsp_Test(
    -- paramters...
)
BEGIN

    -- --------------------------------------------------------------------------
    -- 00 Declaration
    -- --------------------------------------------------------------------------

        DECLARE error_InvalidInputs      CONDITION FOR SQLSTATE 'HY000'; 



       DECLARE EXIT HANDLER FOR SQLEXCEPTION
        BEGIN
            ROLLBACK;
            GET DIAGNOSTICS CONDITION 1 @var_SqlState = RETURNED_SQLSTATE, @var_MessageText = MESSAGE_TEXT, @var_MySqlErrorNo = MYSQL_ERRNO, @var_SchemaName = SCHEMA_NAME, @var_TableName = TABLE_NAME;

            SET @var_FullError = CONCAT("ERROR: ", @var_MySqlErrorNo, " (", @var_SqlState, "): ", @var_MessageText, "Scheman Name: ", @var_SchemaName, "Table Name: ",@var_TableName);

            SET @var_ErrorMessage = CONCAT(@var_ErrorMessage,';;;;;', @var_FullError);
            SELECT @var_ErrorMessage;
            RESIGNAL ;
        END;


        SET @var_ErrorMessage = '';

        SET @var_ErrorMessage = CONCAT(@var_ErrorMessage,'Error message: = Now; ');

        -- update statement here

        SET @var_ErrorMessage = CONCAT(@var_ErrorMessage,'Error message: = Now; ');


    SELECT 1 as UpdatedSuccessfully;
END//
DELIMITER ;
Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
Kaushik
  • 2,072
  • 1
  • 23
  • 31

0 Answers0