gpt4 book ai didi

.net - 从SQL错误消息547获取特定信息

转载 作者:行者123 更新时间:2023-12-03 08:01:45 30 4
gpt4 key购买 nike

如何正确从sql错误消息编号547中提取特定信息?

所需信息:

  • 表名称
  • 约束名称
  • 列名

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

    End If
    End Try

    样本消息:

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

    最佳答案

    没有直接获取这些信息的直接方法。

    所有这些都串联到错误消息中。

    您可以使用select * from sys.messages where message_id=547来查看消息的各种不同语言格式,以便提取组成部分,然后可以使用正则表达式来捕获基于此信息的组。

    关于.net - 从SQL错误消息547获取特定信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8205675/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com