Solved

Test ODBC Connection

Posted on 2013-06-21
1
419 Views
Last Modified: 2013-06-27
I have an ODBC connection set up to a local server but i want to test certain functions on the database when i am offline.

How can i test the state of the ODBC link prior to trying to opening it?

Set cn = New ADODB.Connection
With cn
    .Provider = connBesp(0)
    .Properties("Data Provider").Value = connBesp(1)
    .Properties("Data Source").Value = connBesp(2)
    .Properties("User ID").Value = connBesp(3)
    .Properties("Password").Value = connBesp(4)
    .Properties("Initial Catalog").Value = connBesp(5)
    .Open
End With

Any help welcome
0
Comment
Question by:SweetingA
1 Comment
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
ID: 39267433
Hi,

you cannot see if the connection WOULD be opened before you try to do so. You could maybe use some methods like ping to see if the server is available but that's much work to do.

The simplest method is to perform the Open method and use an "On Error Resume Next" before, that you can catch the error with "If Err.Number <> 0 Then...". Don't forget to disable this by using "On Error Goto 0" (or Goto your error handling).

ADO has an additional "Errors" collection in the connection object which you can then read out to find out the exact reason. ADO saves also more than one error if they occurred in an operation so you must cycle through the Errors list to find out all.

Cheers,

Christian
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question