How I can check if connection ti sql server is established with vba

MBMSOFT

Registered User.
Local time
Today, 18:04
Joined
Jan 29, 2010
Messages
90
How I can check if connection to SQL server is established with VBA before the SQL is executed
btw I use VPN connection to connect to sql server, and some times VPN connection is going down in middle of work and it is quite unconvinied
 
Last edited:
Your connection has probably been declared with a name.
Don't confuse the name of the function that opens the connection with the name of the actual connection.

If so, ConnectionName.State should equal 1 if connected and 0 if not.

So:
Code:
If ConnectionName.State = 0 then OpenConnectionFunction
 
if you're also needing to check the status of the VPN, then you may want to check that statuts first.

If you hve a mapped drive only visible when you're VPN is connected, something like:
GetAttr TestPath will throw an error if it cannot be seen.
(Where "TestPath" is a string containing some path that only exists when your VPN is up)

I would not be supprized if somebody else may have some pre-developed way to use one of the Win32_ Class methods.
I'm sure there is some, and I've used some of the various Classes and methods but I've not preveiously developed anything specific to that.

One thing for sure would be the Win32_MappedLogicalDisk Class but there may be others.

The thing is though, none is probably fewer lines of code than the simple "GetAttr" and watch for an error.
 

Users who are viewing this thread

Back
Top Bottom