简体   繁体   English

从连接读取数据时出错

[英]Error reading data from the connection

We have written several C# web services that have a connection to our internal Firebird 2.5.5 database. 我们已经编写了几个与内部Firebird 2.5.5数据库连接的C#Web服务。

Unfortunately the exception "Error reading data from the connection" is thrown more and more often and we don't know how to fix it. 不幸的是,越来越多地抛出“从连接中读取数据时出错”的异常,我们不知道如何解决。

We tried to disable pooling but this did not have the desired effect. 我们试图禁用池化,但这没有达到预期的效果。

We also wrote a try catch block that reconnects and re-executes the SQL, but this does not seem to us to be the right solution. 我们还编写了一个try catch块来重新连接并重新执行SQL,但是在我们看来,这似乎不是正确的解决方案。

Is there another option? 还有其他选择吗?

Here are some environment informations: 以下是一些环境信息:

  • C# 7.0 C#7.0
  • .NET 4.5 .NET 4.5
  • Firebird Version 2.5.5 火鸟版本2.5.5
  • Firebird Driver 5.5.0 火鸟驱动程序5.5.0
  • The Firebird log does not show any error messages at that time Firebird日志当时不显示任何错误消息
  • The error happens from time to time with any sql statement 该错误有时会通过任何sql语句发生

The problem is relatively simple: the network connection between client and server is interrupted or broken for some reason, but the State of the client connection remains Open - even though you cannot use that connection anymore. 这个问题比较简单:客户端和服务器之间的网络连接中断或损坏出于某种原因,但State的客户端连接仍然Open -即使你不能使用该连接了。 Unfortunately Firebird decided to not update this status to Broken automatically, which would make a lot more sense if you ask me. 不幸的是,Firebird决定不将此状态自动更新为Broken ,如果您问我,这将更有意义。

You already figured out that reopening the connection "somewhat fixes" the problem, and we have discussed that you could do this only when FbException.ErrorCode is 335544726. 您已经发现重新打开连接可以“一定程度上解决”该问题,并且我们已经讨论了仅当FbException.ErrorCode为335544726时才可以执行此操作。

Unfortunately this does mean that any open transaction is also lost, and you cannot commit any data from it anymore. 不幸的是,这确实意味着任何未完成的事务也会丢失,并且您无法再提交任何数据。 The only way I could think of to reliably recover from this situation is to rethrow the exception: 我能想到的从这种情况中可靠恢复的唯一方法是抛出异常:

try
{
    // ...
}
catch (FbException ex)
{
    if (ex.ErrorCode == 335544726)
    {
        // close the connection (reopen depending on your application)
    }

    throw;
}

This way, you can catch this exception at a higher level in your application, and deal with it however is appropriate at that point - ie. 这样,您可以在应用程序的更高级别上捕获此异常,并在那时进行处理(即,适当的处理)。 retrying the entire transaction, or letting the user choose what to do. 重试整个交易,或让用户选择要执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM