Procedure or function expects parameter which was not supplied: how to fix
Codemia Knowledge Hub ·
The SQL Server error "Procedure or function expects parameter which was not supplied" means the stored procedure definition requires a parameter that your calling code did not provide. The usual causes are a forgotten parameter, a C# null passed instead of DBNull.Value, a misspelled parameter name, or a missing CommandType.StoredProcedure.
The message names both the procedure and the missing parameter:
The fix looks obvious, but the root cause can be subtle, especially when stored procedures evolve independently from the application code.
The parameter is missing from the call
Given this procedure:
C# code that omits the required @UserId fails:
Add the missing parameter:
Passing C# null instead of DBNull.Value
This is the most deceptive cause. If you pass a C# null as a parameter value, ADO.NET silently skips the parameter instead of sending SQL NULL, and SQL Server reports it as not supplied:
Use DBNull.Value when the value is null, so SQL NULL is actually sent:
Parameter name mismatch
A typo makes SQL Server see an unrecognized parameter while the required one appears missing:
SQL Server parameter names are case-insensitive, so @UserId and @USERID both work, but @User_Id is a different name and triggers the error.
Optional parameters and removed defaults
A parameter with a default value does not need to be supplied:
Only @SearchTerm is required here. If a later schema change removes a default, or adds a new required parameter, and the application code is not updated, the error appears.
Forgetting CommandType.StoredProcedure
Without CommandType = CommandType.StoredProcedure, the command text is interpreted as raw SQL instead of a procedure call, so the parameters you added are not bound to the procedure.
Debugging steps
- Check the procedure definition in SQL Server Management Studio to see every parameter and which have defaults:
- Log the parameters your application actually sends before executing:
- Run the same call directly in SSMS with the same values to confirm it works outside your application.
Related reading
- Programmatically flush data to cassandra every time before cassandra shut down
- Promote secondary to primary from secondary node
- Proper Realm usage patterns/best practices?
- Properly close mongoose's connection once you're done
- Process finished with exit code -1073740791 0xC0000409 STATUS_STACK_BUFFER_OVERRUN
- Process finished with exit code 1 Spring Boot Intellij
- Pros and cons of multi-leader vs leaderless replication in databases?
- Provision multiple logical databases with Terraform on AWS RDS cluster instance
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.