Solved

Test ODBC Connection

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now