where is IDbException

  • Thread starter Thread starter Andy Fish
  • Start date Start date
A

Andy Fish

Hi,

I have done a bit of programming against the System.Data.SqlClient classes
but in order to maintain some prospect of database portability in my code I
would prefer to use the more general IDbConnection, IDbCommand etc.

However, I notice there is no corresponding IDbException, and the
documentation for the IDbXXX interfaces does not mention any exceptions that
might be thrown.

Am I correct in thinking that using the more general IDbXXX interfaces is a
good practice? - it seems silly to tie myself unnecessarily to one database
provider implementation? If so, how should I manage database exceptions?

Thanks in advance for any responses. Even if there is no nice answer, it
would be good to know that I'm not overlooking something obvious

Andy
 
Hi Andy,

Exceptions are provider specific and seems to me that they are all derived
from SystemException.
Why yould you need IDbException anyway?
Anyway, those exceptions normally hold provider specific data within
InnerException property which is even more database specific :-).
 
Andy Fish said:
Hi,

I have done a bit of programming against the System.Data.SqlClient classes
but in order to maintain some prospect of database portability in my code I
would prefer to use the more general IDbConnection, IDbCommand etc.

However, I notice there is no corresponding IDbException, and the
documentation for the IDbXXX interfaces does not mention any exceptions that
might be thrown.

Am I correct in thinking that using the more general IDbXXX interfaces is a
good practice? - it seems silly to tie myself unnecessarily to one database
provider implementation? If so, how should I manage database exceptions?

Thanks in advance for any responses. Even if there is no nice answer, it
would be good to know that I'm not overlooking something obvious

Well the obvious thing is just to treat them as base Exceptions.
Exception.ToString() will display most of the usefull details. If you need
to discover at runtime the exact cause of a database exception you will need
to downcast the Exception to its provider type.

David
 
Thanks for this reply

I have done a bit of reading about this subject, and the arguments on both
sides of the "checked exception" question (search for IDbConnection
exception on google groups).

Suffice to say I am a fan of checked exceptions so I think this sucks. JDBC
is far from perfect in this respect but at least makes some attempt to
include exception conditions in the interface contract.

Anyway I've no wish to start yet another flame war on the subject (but if
anyone else wants to, I'll see you outside in the car park :-)

Andy

Miha Markic said:
Hi Andy,

Exceptions are provider specific and seems to me that they are all derived
from SystemException.
Why yould you need IDbException anyway?
Anyway, those exceptions normally hold provider specific data within
InnerException property which is even more database specific :-).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Andy Fish said:
Hi,

I have done a bit of programming against the System.Data.SqlClient classes
but in order to maintain some prospect of database portability in my
code
I
would prefer to use the more general IDbConnection, IDbCommand etc.

However, I notice there is no corresponding IDbException, and the
documentation for the IDbXXX interfaces does not mention any exceptions that
might be thrown.

Am I correct in thinking that using the more general IDbXXX interfaces
is
a
good practice? - it seems silly to tie myself unnecessarily to one database
provider implementation? If so, how should I manage database exceptions?

Thanks in advance for any responses. Even if there is no nice answer, it
would be good to know that I'm not overlooking something obvious

Andy
 
Back
Top