Consulting

Results 1 to 3 of 3

Thread: vba code to test odbc connection

  1. #1
    VBAX Regular
    Joined
    Feb 2008
    Posts
    9
    Location

    vba code to test odbc connection

    How can i test an ODBC connection in VBA code.
    I use DAO recordsets.
    I know this question is already been raised on this forum, but it's never been answered.
    I'd like to write a function like TestConnection = true or false or something
    The connection string is like :
    "ODBC;DATABASE=namedatabase;DESCRIPTION=x;DSN=x;OPTION=2346;PWD=x;PORT=0;SE RVER=x;UID=x"

    Any help would be appreciated alot

  2. #2
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    DAO probably has an Errors collection, but IMHO ADO is probably a better route; and I would think you would want to emply DNS-less Connection Strings. Anyway, check out the errors collection here.


    http://www.w3schools.com/ado/ado_ref_connection.asp

    .02 Stan

  3. #3
    VBAX Regular
    Joined
    Feb 2008
    Posts
    9
    Location

    problem solved !

    Hi Stan,

    Thanx for the reply. I've used your ADO-way. This is the code that
    works for me.

    Dim con
    Set con = CreateObject("ADODB.Connection")
    con.Open CONNSTRINGS
    con.Close
    Set con = Nothing

    Where CONNSTRINGS is my connection string.

    If the server is not online, my error trap gives the "no connection" message.

    Thanks alot.

    I'm new to ODBC connection. I'm gonna check out the differences between DSN and DSNless connections, because that's all a bit of Chinese for me right now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •