Solved

Test ODBC Connection

Posted on 2013-06-21
1
420 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

713 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