c# - WPF MySQL connection error handling -


i try error handling when comes connecting mysql database. want separate out connection errors , sql errors. issue being error being returned doesn't seem mysql error in fact ms error. doing:

using (mysqlconnection con = new mysqlconnection(constring)) {     mysqldataadapter da = new mysqldataadapter();     mysqlcommand cmd = new mysqlcommand(sqlcmd, con);     try     {         system.security.cryptography.rsacryptoserviceprovider.usemachinekeystore = true;         var provider = new system.security.cryptography.rsacryptoserviceprovider();         con.open();         da.selectcommand = cmd;         da.fill(dt);         con.close();     }     catch (exception x)     {         //amazing error catching code     } } 

now lets try connect machine not have mysql installed, exception being returned:

mysql.data.mysqlclient.mysqlexception (0x80004005): unable connect of specified mysql hosts. @ mysql.data.mysqlclient.nativedriver.open() @ mysql.data.mysqlclient.driver.open() @ mysql.data.mysqlclient.driver.create(mysqlconnectionstringbuilder settings) @ mysql.data.mysqlclient.mysqlpool.getpooledconnection() @ mysql.data.mysqlclient.mysqlpool.trytogetdriver() @ mysql.data.mysqlclient.mysqlpool.getconnection() @ mysql.data.mysqlclient.mysqlconnection.open()

now googling "0x80004005 mysql" returns multiple threads on stack overflow c# connecting mysql. doing search 0x80004005 returns windows xp error message page.

so leaves me question best way determine connection error vs sql error message?

why not perform catches on different exception types mysql connector can thrown. (not exact exception types) like

try { }catch(mysqlconnectionexception) { }catch(mysqlqueryexception ) { } 

you can catch , handle more 1 type of exception, general exception. other need drill general exception , determine underlying exception type. take @ example well

https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-errors.html


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -