Solved

Test ODBC Connection

Posted on 2013-06-21
1
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

634 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