Where would I put a Try/Catch statement to check if a user has an ODBC driver for my app, and what exception do I use?
CP
Printable View
Where would I put a Try/Catch statement to check if a user has an ODBC driver for my app, and what exception do I use?
CP
I'm putting this in the Form_Load routine since I already know it's an ODBC exception:
VB Code:
Dim odbcerr As New frmDriverError Try con.ConnectionString = "my;super;long;connection;string" Catch ox As Odbc.OdbcException odbcerr.ShowDialog() End Try
And so the frmDriverError form has a link to download the right driver.
Is this the right place to put this?
Thanks,
CP
no because all you are doing there is setting a string property of the con object. You want to error catch when you actually try to use the connection. Generally this is when you call the OPEN method of the connection. That will throw an error if it fails, which is what you are going to want to catch
Perfect, thanks Matt.
Of course I don't know it if will really work because I can't duplicate the error on my machine because, naturally, I already have the drivers; or if I'm even directing the user to download the right thing... odbc_net.msi for connecting to a PostgreSQL db, but I think so.