Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am making a transaction procedure in my sql, but I want to send a message-error
If the register already exists before I insert.

For example:

CREATE DEFINER=`root`@`localhost` PROCEDURE `AsigPolizClau` //.......--->more code
  BEGIN
  
  START TRANSACTION;
  
    IF((SELECT id FROM poliza where field1=fk_field1) IS NULL) THEN    
      BEGIN
        /*
          ...
          ...
        */
      END;
   ELSE
      BEGIN
       //HERE I WANT TO SEND A MESSAGE ERROR!!!!!!!! (HOW????????)
       //HERE I WANT TO SEND A MESSAGE ERROR!!!!!!!! (HOW????????)
       //HERE I WANT TO SEND A MESSAGE ERROR!!!!!!!! (HOW????????)
      END;
   END IF;

   SET a=(SELECT @@error_count);
   IF a > 0 THEN
    ROLLBACK;
   ELSE
    COMMIT;
   END IF;   


  END


I want that the procedure finished and send a message error to my
MySqlCommand variable in C#.
and I give a message from my C# code, maybe a message pased from sql procedure to
the procedure in c#.

It is posible???

Thanks in advance!!
Posted

SqlDataReader dr = cmd.ExecuteReader(); 
dr.Read().ToString(); <-- error is returned here
 
Share this answer
 
As far as I know there's no direct mechanism. One workaround is for example that you:
- return information from the stored procedure if it succeeds or not (like 0/1)
- in the procedure you add descriptive rows about the error to a custom error table
- in the calling application if you receive 0 you read the messages from the error table
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900