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
精彩评论