views:

553

answers:

1

I'm calling a stored procedure on a SQL Server 2005 database which returns an XML resultset. Sometimes it will return an null resultset becuase there are not rows to return. When this happens athe ExecuteXmlReader method throws a TargetInvocationException. This seems to be a known issue (see: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/5e90e3c0-605b-406d-848a-dea7b16f458e/).
What is the best way to handle this exception?

+1  A: 

I can think of 3 choices

  1. Modify stored procedure to return a dummy/empty value
  2. Modify code - catch exception and do nothing - or log error
  3. Use DataSet - You should get an empty DataSet so just check if DataSet is empty or not.

As a related SO post for the 3rd choice, here is a SO question on how to check if DataSet is empty or not

In C#, what is the best way to test if a dataset is empty?

Sung Meister