开发者

How to stop connecting to Mysql (from Excel) after X number of seconds have gone past

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


You can use ADODB.Connection's ConnectionTimeout property:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜