我可以配置 LLBLGen 以将生成的 SQL 包含在异常中吗?

发布于 2024-10-14 15:29:29 字数 1170 浏览 2 评论 0原文

我正在使用 LLBLGen,并且有一些如下代码:

    if (onlyRecentMessages)
    {
        messageBucket.PredicateExpression.Add(MessageFields.DateEffective >= DateTime.Today.AddDays(-30));
    }

    var messageEntities = new EntityCollection<MessageEntity>();
    using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
    {
        myAdapter.FetchEntityCollection(messageEntities, messageBucket);
    }

我当前在 FetchEntityCollection 行上收到 SqlException。错误是: System.Data.SqlClient.SqlException:传入的表格数据流 (TDS) 远程过程调用 (RPC) 协议流不正确。此 RPC 请求中提供了太多参数。最大值为 2100。

但这是一个旁注。我真正想要做的是将生成的 SQL 包含在代码中的自定义异常中。例如这样的事情:

 using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
        {
            try
            {
               myAdapter.FetchEntityCollection(messageEntities, messageBucket);
            }
            catch (SqlException ex)
            {
               throw new CustomSqlException(ex, myAdapter.GeneratedSqlFromLastOperation);
            }
        }

当然,不存在诸如GenerateSqlFromLastOperation 之类的属性。我知道我可以配置日志记录,但我更愿意将信息直接放在堆栈跟踪/异常中,以便我现有的异常日志记录基础结构可以在发生此类错误时为我提供更多信息。

谢谢! 史蒂夫

I'm using LLBLGen and I have some code like so:

    if (onlyRecentMessages)
    {
        messageBucket.PredicateExpression.Add(MessageFields.DateEffective >= DateTime.Today.AddDays(-30));
    }

    var messageEntities = new EntityCollection<MessageEntity>();
    using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
    {
        myAdapter.FetchEntityCollection(messageEntities, messageBucket);
    }

I'm currently getting a SqlException on the FetchEntityCollection line. The error is:
System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.

but that's a side note. What I actually want to be able to do is include the generated SQL in a custom exception in my code. So for instance something like this:

 using (var myAdapter = PersistenceLayer.GetDataAccessAdapter())
        {
            try
            {
               myAdapter.FetchEntityCollection(messageEntities, messageBucket);
            }
            catch (SqlException ex)
            {
               throw new CustomSqlException(ex, myAdapter.GeneratedSqlFromLastOperation);
            }
        }

Of course, there is no such property as GeneratedSqlFromLastOperation. I'm aware that I can configure logging, but I would prefer to have the information directly in my stack track / exception so that my existing exception logging infrastructure can provide me with more information when these kinds of errors occur.

Thanks!
Steve

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

横笛休吹塞上声 2024-10-21 15:29:29

您应该得到一个 ORMQueryExecutionException,其中包含描述中的完整查询。查询的执行方法将所有异常包装在 ORMQueryExecutionException 中,并将查询存储在描述中。

ps:如果可能的话,请在我们的论坛上询问 llblgen pro 相关问题,因为我们不经常监控 stackoverflow。谢谢。 :)

You should get an ORMQueryExecutionException, which contains the full query in the description. The query's execute method wraps all exceptions in an ORMQueryExecutionException and stores the query in the description.

ps: please, if possible ask llblgen pro related questions on our forums, as we don't monitor stackoverflow frequently. Thanks. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文