repeating OdbcException C#

霸气de小男生 提交于 2019-12-12 02:35:57

问题


I am using OdbcConnection class to connect to an external database. As a part of this process, I am also trying to handle the various exceptions thrown by this class (OdbcException). I find that the OdbcException contains a list called Errors which has multiple OdbcErrors.

If I provide wrong credentials, I am able to get the access denied error but they are repeated twice in the errors list. The Errors list contains two errors but they are not unique. At the user end I see :

ERROR [HY000] [MySQL][ODBC 5.3(w) Driver]Access denied for user 'xx'@'xxx.com' (using password: YES)
ERROR [HY000] [MySQL][ODBC 5.3(w) Driver]Access denied for user 'xx'@'xxx.com' (using password: YES)

How do I handle this situation and make them unique? I tried doing it manually by creating a new OdbcException and removing the repeated error item in the list but I couldn't do that. (I guess odbcexception doesn't have a public constructor). Is creating a custom exception that mocks the same odbc exception the only way? How will I create a custom exception? Should it inherit OdbcException or DbException?

来源:https://stackoverflow.com/questions/38209450/repeating-odbcexception-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!