The number of parameters does not match number of values for stored procedure.
description
When calling Database.ExecuteNonQuery(stringStoredProcedureName, params object[] parameterValues) (and perhaps other methods as well; I haven't tested to see) Enterprise Library incorrectly returns an InvalidOperationException with the messasge "The number of parameters does not match number of values for stored procedure." when the number of parameters are correct.
In one case, against SQL Server 2005, the problem was that the sql user account was not dbo but the stored procedure being called was in the dbo schema. The sql user account did have permission to execute the stored procedure. The storedProcedureName provided to the method did not include the schema name; it was in the form of "MyProcedure". Changing the storedProcedureName to "dbo.MyProcedure" worked around the issue but there was absolutely no relationship in this issue to the number of parameters. In fact, SQL Server does not object to leaving the schema out. This requirement appears to be another programming flaw in Enterprise Library.
The appropriate behavior, as is the behavior in other areas within the DAAB, is to simply pass on any SqlException that occurs. Substituting an InvalidOperationException is inappropriate to the condition I experienced and, in fact, is inappropriate for an invalid number of parameters. SQL Server and ADO.Net raise a perfectly appropriate exception when there are missing parameters in the form of "Procedure or Function 'MyProcedure' expects parameter '@ParameterName', which was not supplied."
When calling Database.ExecuteNonQuery(DbCommand command) with parameters created using AddInParameter(), and the number of parameters is incorrect, the library passes the SqlException from SQL Server as it should. This is the behavior that should occur when calling all forms of ExecuteNonQuery.
Non-matching parameter lists - whether by type or by number - are design-time issues that, once an application is in production, should rarely if ever occur. It is not necessary, is of little value, and in this case is even harmful, for Enterprise Library to try to handle the exception in code.
Thanks,
Dale