Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters that belong to a stored procedure on a SQL Server before I actually execute it?
I have an a ‘multi-environment’ scenario where there are multiple versions of the same database schema. Examples of environments might be ‘Development’, ‘Staging’, & ‘Production’. ‘Development’ is going to have one version of the stored procedure and ‘Staging’ is going to have another.
All I want to do is validate that a parameter is going to be there before passing it a value and calling the stored procedure. Avoiding that SqlException rather than having to catch it is a plus for me.
Joshua
You can use SqlCommandBuilder.DeriveParameters() (see SqlCommandBuilder.DeriveParameters – Get Parameter Information for a Stored Procedure – ADO.NET Tutorials) or there’s this way which isn’t as elegant.