Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用MS SQL数据库从.Net中的异常(引用)获取表名_C#_Sql_Sql Server - Fatal编程技术网

C# 如何使用MS SQL数据库从.Net中的异常(引用)获取表名

C# 如何使用MS SQL数据库从.Net中的异常(引用)获取表名,c#,sql,sql-server,C#,Sql,Sql Server,我的代码- try { currentPane.ViewController.Delete(); } catch (Exception ex) { try { /* -- Need to find the Expression for getting the Table Name -- */ string title = "DeleteButton_Click Error " + cont

我的代码-

try
    {
        currentPane.ViewController.Delete();
    }
    catch (Exception ex)
    {
        try
        {
/* -- Need to find the Expression for getting the Table Name -- */


            string title = "DeleteButton_Click Error " + contentPane.TabHeader;
            if(ex.InnerException != null)
                MessageBox.Show(ex.InnerException.Message, title, MessageBoxButton.OK, MessageBoxImage.Error);
            else
                MessageBox.Show(ex.Message, title, MessageBoxButton.OK, MessageBoxImage.Error);

            var service = new InsurableRisk.Service.ApplicationExceptionService();
            try
            {
                service.Save(ex);
            }
            catch { }
            finally
            {
                service.Dispose();
                service = null;
            }
        }
        catch
        {
        }
    }
}
在MVVM应用程序中捕获引用完整性异常时,我在ex.InnerException.Message中看到表名

DELETE语句与引用约束“FK_Policy_InsuranceCarrier”冲突。冲突发生在数据库“InsurableRisk”、表“dbo.Policy”、列“InsuranceCarrierKey”中。 声明已终止

但是,我无法计算将提取表名的表达式。
任何指针?

InnerException的类型是什么(即
ex.InnerException.GetType().FullName
return)?@MichaelGunter返回“System.Data.SqlClient.SqlException”看起来需要从字符串中手动提取它。SqlException(及其子SqlError对象)不公开导致错误的表名。依赖异常消息的格式是错误的。它应该是人类可读的文本,而不是机器可读的文本。