与线程的单独 dbx 连接

发布于 2024-08-17 14:16:36 字数 366 浏览 2 评论 0原文

我制作了一个使用 dbx 连接到 mysql 数据库的小应用程序。它在我的本地 mysql 服务器上工作正常,但它应该在远程服务器上工作。

连接到远程服务器需要几秒钟,这会冻结应用程序。

所以我的问题是,如何将连接代码放在不同的线程中?

我必须以某种方式将该连接传递到主线程,以便主窗体上的 dbgrid 正常工作。

我读到在不同线程中工作的数据库内容应该有自己的连接。所以我不确定如何做我想做的事。

有什么想法吗?关于使用远程服务器有什么值得阅读的吗?

谢谢。

编辑:我在表单上使用的组件是:TSQLConnection -> TSimpleDataSet > T数据源> TDB网格。

I made a small app that connects to a mysql db using dbx. It works ok with my local mysql server, but it's supposed to work with a remote server.

Connecting to the remote server takes a few seconds, which freezes the app.

So my question is, how can I put the connection code in a different thread?

I'll have to pass that connection to the main thread somehow, so that the dbgrid I have on the main form works.

I read that db stuff working in a different thread should have their own connections. So I'm not sure how to do what I want.

Any ideas? Anything to read about working with remote servers?

Thanks.

Edit: The components I'm using on the form are: TSQLConnection -> TSimpleDataSet > TDataSource > TDBGrid.

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

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

发布评论

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

评论(2

口干舌燥 2024-08-24 14:16:36

如果您的线程要同时进行数据库访问,则只需每个线程一个连接。基本上,您想要的是一个线程进行连接,并在连接建立后返回给您。您可以在线程中执行此操作,当线程准备好(即建立连接)时,它可以向主线程发送一条消息,让它知道 dbx 连接现在可用。请参阅本教程,了解如何设置线程以及如何在线程与主 VCL 线程之间进行通信。
线程教程

You only need a connection per thread if your threads are going to do simultaneous database access. Basically what you want, is for a thread to connect, and come back to you when the connection has been established. You can do this in a thread, and when the thread is ready (i.e. connection established), it can send a message back to the main thread to let it know that the dbx connection is now available. See this tutorial for ideas on how to set up the thread, and communicate between the thread and the main VCL thread.
Threading Tutorial

撩动你心 2024-08-24 14:16:36

这确实帮助我在 rad studio 中制作多线程应用程序
编写多线程应用程序索引

如果它们还有其他内容,我会尝试帮助

this has really helped me for doing multi thread Apps in rad studio
Writing multi-threaded applications Index

if their is any thing else post and ill try to help

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