获取特定信息从SQL错误信息547 [英] Get Specific Info From SQL Error Message 547

查看:1539
本文介绍了获取特定信息从SQL错误信息547的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何正确地提取特定的信息从一个SQL的错误信息数547?

信息要求:

  • 表名称
  • 约束名称
  • 栏目名称

code:

 尝试
  ....
抓住EX作为System.Data.SqlClient.SqlException
        如果ex.Number = 547然后

        结束如果
结束尝试
 

示例消息:

  

UPDATE语句冲突与列检查约束   CK_Birthdate。发生在数据库'罗斯文,表中的冲突   员工,列出生日期。

解决方案

有单独获得这些信息没有直接的方法。

这一切都被连接成错误消息。

您可以使用 SELECT * FROM sys.messages其中,message = 547 一看就知道你会需要处理,以提取消息的各种不同的语言格式的组成部分,那么也许使用常规EX pressions与围绕该信息的捕获组。

How do I correctly extract specific info from an sql error message number 547?

Info Required:

  • Table Name
  • Constraint Name
  • Column Name

Code:

Try 
  ....
Catch ex As System.Data.SqlClient.SqlException 
        If ex.Number = 547 Then

        End If
End Try

Sample message:

UPDATE statement conflicted with COLUMN CHECK constraint 'CK_Birthdate'. The conflict occurred in database 'Northwind', table 'Employees', column 'BirthDate'.

解决方案

There is no straight forward way of getting these pieces of information separately.

It all gets concatenated into the error message.

You can use select * from sys.messages where message_id=547 to see the various different language formats of the message that you would need to deal with in order to extract the constituent parts then perhaps use regular expressions with capturing groups based around this information.

这篇关于获取特定信息从SQL错误信息547的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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