I need to build a service which expose metadata about stored procedures in an sql server database.
Is there any way to find out which stored procedure return sets, and which don’t, so they can be called, correspondingly, through ExecuteReader or ExecuteNonQuery?
Thank you
It turns out (I Googled) that the way to do this is to set the FMTONLY FLAG to ON on Sql Server.
See here.
Here’s an example taken from here:
In the case where a stored proc does not return any data, you won’t see any output (at least that was my observation in SSMS). When the proc does return data, you see the column names being displayed without actually anything being returned.
So it is sort of a trial an error kind of thing.
NOTE: I tested with a proc that uses a table-valued parameter and it did not produce any output even though the proc does return data. Setting the parameter to NULL did not work and SSMS complained with a nasty error. The error seems to be related to a temp table being used inside the proc and not necessarily with the table-value parameter but still didn’t produce the empty resultset:
Looking at the link posted by Michael, it appears that if the proc returns different result sets depending on a parameter passed in, for example, it’s impossible to know with certainty. See Marc Gravell’s answer.