Solved

Test ODBC Connection

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

752 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