PC Review


Reply
Thread Tools Rate Thread

Abstracting Connection objects

 
 
Frank Rizzo
Guest
Posts: n/a
 
      17th Jul 2003
I have an app that has to connect to various data sources (ms sql server,
sybase, etc...). For this reason I have OdbcConnection, OleDb Connection and
SqlClient objects. When an error happens, I want a single procedure to
handle the error from all the connection types by passing the either the
SqlException, OdbcException or OleDbException.

Unfortunately the object SystemException, that these exceptions have been
derived from, does not have the .Errors collection (like the SqlException,
OdbcException or OleDbException does), so when I pass SystemException into
the procedure and attempt to loop through the Errors collection, it
obviously complains that SystemException does not have such a collection.

Other than overloading the function for each type (which kind of defeats the
purpose of having a single function to handle data related exceptions), can
anyone suggest anything?

--
Frank


 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      17th Jul 2003
Frank,
> Other than overloading the function for each type (which kind of defeats

the
> purpose of having a single function to handle data related exceptions),

can
> anyone suggest anything?


Create proxy objects (Adapter Pattern really) for each type of exception
(Data Source), that your single function can then use to access the errors
collection & error objects, generically.

Alternatively create n+1 routines. One for each of the specific exception
classes, then the +1 that the previous n call passing the errors collection,
generically.

In both of the above, read generically as ICollection or IEnumerable, and
methods found on Object (ToString for example).

I think the proxy objects may be the 'easier' route, as the various errors
collections contain objects of different types. If those objects honor
..ToString, this should be easy, otherwise...

Hope this helps
Jay

"Frank Rizzo" <(E-Mail Removed)> wrote in message
news:uKWtGf$(E-Mail Removed)...
> I have an app that has to connect to various data sources (ms sql server,
> sybase, etc...). For this reason I have OdbcConnection, OleDb Connection

and
> SqlClient objects. When an error happens, I want a single procedure to
> handle the error from all the connection types by passing the either the
> SqlException, OdbcException or OleDbException.
>
> Unfortunately the object SystemException, that these exceptions have been
> derived from, does not have the .Errors collection (like the SqlException,
> OdbcException or OleDbException does), so when I pass SystemException into
> the procedure and attempt to loop through the Errors collection, it
> obviously complains that SystemException does not have such a collection.
>
> Other than overloading the function for each type (which kind of defeats

the
> purpose of having a single function to handle data related exceptions),

can
> anyone suggest anything?
>
> --
> Frank
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help, abstracting classes Snedker Microsoft C# .NET 2 7th May 2009 02:39 AM
Abstracting text Bill Ridgeway Microsoft Excel Misc 3 25th May 2006 04:34 PM
Do you have programs to help a title abstracting business? =?Utf-8?B?SnVzdGluYQ==?= Microsoft Access 2 8th Jan 2006 01:41 AM
abstracting a web service nevin Microsoft C# .NET 2 4th May 2004 11:09 PM
Abstracting and recreating forms Paul Microsoft Dot NET Framework Forms 0 25th Jun 2003 09:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:26 PM.