如何从Sql过程发送消息错误? [英] How I can send a Message Error From My Sql Procedure?

查看:80
本文介绍了如何从Sql过程发送消息错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用sql进行事务处理,但是我想发送一条消息错误
如果在插入之前该寄存器已经存在.

例如:

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



我希望该过程完成,并向我的
发送一条消息错误 C#中的MySqlCommand变量.
然后从C#代码中给出一条消息,也许是一条从sql过程粘贴到
的消息 C#中的过程.

这是可能的吗?

在此先感谢!!



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!!

推荐答案

SqlDataReader dr = cmd.ExecuteReader(); 
dr.Read().ToString(); <-- error is returned here


据我所知,没有直接的机制.例如,一种解决方法是您:
-从存储过程返回信息是否成功(例如0/1)
-在此过程中,将有关错误的描述行添加到自定义错误表中
-在调用应用程序中,如果收到0,则会从错误表中读取消息
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


这篇关于如何从Sql过程发送消息错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆