如何在 X 秒过去后停止连接到 Mysql(从 Excel)
你好 我有一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 ADODB.Connection 的 ConnectionTimeout 属性:
You can use ADODB.Connection's ConnectionTimeout property: