当网络不稳定时,如何防止数据库连接失败?

发布于 2024-07-19 18:39:37 字数 332 浏览 2 评论 0原文

我们有一个使用 BDE 连接到 Oracle DB 的应用程序。
我使用 TQuery 进行 SQL 查询,它连接到 TDatabase,我们不是专业程序员,我们不知道幕后发生了什么。

我们的网络不稳定,存在丢包问题。

当问题发生时,我们的应用程序会与数据库服务器断开连接,或者无法完成当前查询。
处理这个问题的最佳方法是什么?

我们的网络团队目前正在努力解决根本问题,并且我们已经更改了代码以在出现故障时重新连接到数据库。 我们遇到了数据库服务器上打开会话数量的问题。

有什么解决办法吗?
这对我们来说似乎是一个常见问题。

We have a application that uses BDE connected to an Oracle DB.
I use TQuery for the SQL queries, and it connects to TDatabase, we are not professional programmers, and we don't know what happens under the hood.

Our network is unstable, we have an issue with packet loss.

When the problem occurs, our application disconnects from the DB server, or fails to finish the current query.
What is the best way to handle this?

Our networking team is currently working to fix the root issue, and we have changed the code to reconnect to the database when we have a failure. We are running into an issue with the number of open sessions on our database server.

Is there any solution for this?
It appears to be a common issue for us.

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

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

发布评论

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

评论(5

日暮斜阳 2024-07-26 18:39:37

我对数据库组件提出以下建议。

  1. 连接每个 sql 并在完成后关闭。
  2. 使用连接超时& 如果超时,则重新启动查询
  3. 如果数据库断开连接,则将数据假脱机到客户端上的本地数据库,并在再次连接后重新启动到中央数据库的传输。 这样您就不会丢失任何数据。
  4. 使用计时器检查中央数据库连接以对未传输的数据进行假脱机操作。

这个问题在车间数据收集中很常见,上面的建议是我可以有效处理该问题的唯一方法。

I suggest the following on Database Component.

  1. do connect on every sql and close on completion.
  2. Use connection timeout & restart query if there is a timeout
  3. If database is disconnected, spool the data to a local database on the client and restart transmission to the central database once there is connectivity again. This way you do not loose any data.
  4. Use a timer to check for central Database connectivity to do spooling of untransmitted data.

This problem is common for shopfloor data collection and the suggestion above is the only way I could effectively handle the problem.

海拔太高太耀眼 2024-07-26 18:39:37

尝试实现一个“看门狗”线程:

  1. 每 X 秒 Ping 一次网络(数据库服务器的 IP 地址)
  2. 如果不可用,则禁用 UI 并尝试再次连接

考虑到任何事务可能根本不会成功,并保存它某处的信息。 然后,在通过“看门狗”线程连接时,如果事务的性质允许的话,尝试再次执行该事务。

Try to implement a "watchdog" thread that :

  1. Pings the network (IP address of the database server) every X seconds
  2. If unavailable then disables the UI and try to connect again

Take into account that any transaction might not succeed at all, and save that information somewhere. Then, upon connecting via "watchdog" thread, try to preform that transaction again, if the nature of transaction allows so.

长途伴 2024-07-26 18:39:37

采用 n 层解决方案也可能有所帮助...特别是如果中间层也在数据库服务器上,因此其连接是本地的。 Delphi 最近的大多数实现都使用自定义 HTTP 服务器作为中间层,这样做的优点是仅在当前执行的请求时才需要连接。一旦请求完成,可以毫无问题地断开连接。

Going to an n-tier solution might also help... especially if the middle tier is also on the database server so its connection is local. Most of the recent implementations for Delphi use a custom HTTP server as the middle tier, the advantage of such is that the connection is only required for the current request being performed..once the request is complete, the connection can be severed without any problems.

还如梦归 2024-07-26 18:39:37

抱歉,答案很简短......修复您的网络。 这确实是目前最适合您的选择。

Sorry for the short answer... fix your network. That is really the best option for you at this point.

十级心震 2024-07-26 18:39:37

使用 DBExpress 技术代替 ADO 或其他任何技术。 dbquery + provider + Clientdataset 的结构在设计上是“断开连接”的。

您可以简单地测试打开数据集、断开连接、重新连接并发布数据。

顺便说一句,使用 DBExpress 可以轻松地将应用程序升级到 n 层场景。

Use DBExpress technology instead of ADO of anything else. The structure dbquery + provider + Clientdataset is "disconnected" by design.

You can test simply opening a dataset, drop the connection, reconnect and post the data.

By the way, with DBExpress it's easy to upgrade an application to a n-tier scenario.

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