repeating OdbcException C#

2019-09-12 04:49发布

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?

0条回答
登录 后发表回答