Procedure expects parameter which was not supplied
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The error "Procedure or function expects parameter which was not supplied" is one of the most common SQL Server errors developers encounter when calling stored procedures from application code. It means the stored procedure definition requires a parameter that your calling code did not provide. Understanding why this happens and how to fix it will save you significant debugging time, especially in larger codebases where stored procedures evolve independently from the application layer.
What the Error Looks Like
When SQL Server throws this error, you typically see a message like:
This tells you exactly which stored procedure failed and which parameter is missing. The fix seems obvious, but the root causes can be subtle.
Common Causes
Missing Parameter in Application Code
The most straightforward cause is simply forgetting to add a parameter when calling the stored procedure from C# or another language. Consider this stored procedure:
If your C# code omits the required @UserId parameter, you get the error:
The fix is to add the missing parameter:
Passing null Instead of DBNull.Value
This is the most deceptive cause. In C#, if a variable is null and you pass it directly as a parameter value, ADO.NET silently ignores the parameter entirely rather than sending a SQL NULL. SQL Server then complains that the parameter was not supplied:
The solution is to use DBNull.Value when the value is null:
This pattern ensures that a SQL NULL is sent to the server instead of the parameter being omitted.
Parameter Name Mismatch
A typo in the parameter name causes SQL Server to treat it as an unrecognized parameter while the required one appears missing:
SQL Server parameter names are case-insensitive, so @UserId and @USERID both work. However, @User_Id is a completely different parameter name and will cause the error.
Optional Parameters in SQL Server
SQL Server supports optional parameters with default values. If a parameter has a default, you do not need to supply it:
Only @SearchTerm is required here. However, if you later remove the default value during a schema change and forget to update the application code, the error appears.
How to Debug
When you encounter this error, follow these steps:
First, check the stored procedure definition in SQL Server Management Studio to see all parameters and which ones have defaults:
Second, log or inspect the parameters your application is actually sending. In C#, you can iterate over the parameter collection before executing:
Third, test the stored procedure call directly in SSMS with the same parameter values to confirm it works outside your application.
Common Pitfalls
- Passing C#
nullinstead ofDBNull.Value, which silently drops the parameter from the call - Misspelling a parameter name (e.g.,
@UserIDvs@User_Id) and not realizing it - Updating a stored procedure to add a new required parameter without updating all calling code
- Using
AddWithValuewith a value ofnulland assuming SQL Server receives NULL - Forgetting to set
CommandType = CommandType.StoredProcedure, which causes the command text to be interpreted as raw SQL instead
Summary
- The error occurs when a stored procedure's required parameter is not included in the call from application code
- The most common hidden cause is passing C#
nullinstead ofDBNull.Value, which silently omits the parameter - Always use the
(object)value ?? DBNull.Valuepattern when a parameter might be null - Check for parameter name mismatches between your code and the stored procedure definition
- Use
sp_helptextor SSMS to verify which parameters are required and which have defaults - Log your parameter names and values before execution to catch issues early

