|
-
Jan 4th, 2003, 04:34 PM
#1
Thread Starter
New Member
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!"
-
Jan 4th, 2003, 04:43 PM
#2
PowerPoster
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.
-
Jan 4th, 2003, 04:51 PM
#3
Thread Starter
New Member
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!"
-
Jan 4th, 2003, 05:01 PM
#4
Addicted Member
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
-
Jan 4th, 2003, 07:27 PM
#5
Thread Starter
New Member
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!"
-
Jan 4th, 2003, 08:02 PM
#6
PowerPoster
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
-
Jan 4th, 2003, 09:13 PM
#7
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|