如何在 X 秒过去后停止连接到 Mysql(从 Excel)

发布于 2024-10-10 11:50:55 字数 316 浏览 0 评论 0原文

你好 我有一些 VBA 代码,它首先连接到远程服务器中的 MySQL 数据库,然后查询它。

有时 MySQL 数据库不可用(服务器停机、互联网连接问题等),但连接 VBA 代码(参见下面的代码,第二行)会持续几分钟,这对用户来说相当令人沮丧。

...
Set oConn = New ADODB.Connection    
oConn.Open connection_string
...

有没有办法在使用 VBA 25 秒后停止,以便显示一条消息,例如“服务器似乎已关闭。请联系您的系统管理员”?

预先感谢您的帮助

Hi
I have some VBA code which first connects to a MySQL database in remote server, then it queries it.

Sometimes the MySQL database is not available (server down, internet connection problem, etc) but the connecting VBA code (see code below, 2nd line) goes on for minutes, which is rather frustrating for the user.

...
Set oConn = New ADODB.Connection    
oConn.Open connection_string
...

Is there a way to stop after, say 25 seconds with VBA so a message can be displayed like "Server seems to be down. Please contact your system admin" ?

Thanks in advance for your help

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

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

发布评论

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

评论(1

千秋岁 2024-10-17 11:50:55

您可以使用 ADODB.Connection 的 ConnectionTimeout 属性:

Set oConn = New ADODB.Connection
oConn.ConnectionTimeout = 25
oConn.Open connection_string

You can use ADODB.Connection's ConnectionTimeout property:

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