Results 1 to 7 of 7

Thread: Checking for errors in ODBC-connections

  1. #1

    Thread Starter
    New Member PeeWee's Avatar
    Join Date
    Jan 2003
    Location
    Nybro, Sweden
    Posts
    15

    Question Checking for errors in ODBC-connections

    Greetings and salutations!
    I'm working on a small app that connects to a MySQL-server to retrieve information. It uses an ODBC-driver to do so. However, if I give wrong information to the connectiostring (such as wrong host name) the debug crashes on me. I want to do a test connection, to check if the host name is correct, and if the user name and password are correct, but I don't know how....

    Any help in this matter is deeply appreciated.

    Yours,
    Peter Wilhelmsson aka. Muawije @ Demon's Gate MUD
    "Two wrongs won't make one right, but three left does!"

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Simply handle the exception(s) with a try...catch block. There is probably an ODBCException that you can catch, or even dig down more specifically.

  3. #3

    Thread Starter
    New Member PeeWee's Avatar
    Join Date
    Jan 2003
    Location
    Nybro, Sweden
    Posts
    15
    Okiday!
    Problem is, how would you write such a try..catch-block, cause I have no idea... =)

    Does the term "n00b" ring a bell, anyone?
    "Two wrongs won't make one right, but three left does!"

  4. #4
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    Originally posted by PeeWee
    Okiday!
    Problem is, how would you write such a try..catch-block, cause I have no idea... =)

    Does the term "n00b" ring a bell, anyone?
    http://support.microsoft.com/default...b;en-us;310985

    Code:
        Try
        cn.Open()
        Catch ex as OdbcException
        MsgBox(ex.Message)
        Finally
        cn.Close()
        End Try
    -Shurijo

  5. #5

    Thread Starter
    New Member PeeWee's Avatar
    Join Date
    Jan 2003
    Location
    Nybro, Sweden
    Posts
    15
    Ok, I got that to work. Whenever anything goes wrong with the connection, I get the error message nice and friendly. But where in that statement (or in the error display function) do I print the message that all went fine, the "COnnection succesful!" message?
    "Two wrongs won't make one right, but three left does!"

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    To add to the above code.
    Code:
        Try
             cn.Open()
             MsgBox("Connection opened just fine.")
        Catch ex as OdbcException
             MsgBox(ex.Message)
        Finally
             MsgBox("Now closing the connection.")
             cn.Close()
        End Try
    Check out this link:
    http://search.microsoft.com/default....&siteid=us/dev

  7. #7

    Thread Starter
    New Member PeeWee's Avatar
    Join Date
    Jan 2003
    Location
    Nybro, Sweden
    Posts
    15
    It works great! Here I am, with Visual Studio in my hands, and have to re-learn everything from the start, basically... =)

    Thanks! Prepare for a lot more questions later on!
    "Two wrongs won't make one right, but three left does!"

Posting Permissions

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



Click Here to Expand Forum to Full Width