SQL Server Error 119 occurs when you attempt to execute a stored procedure or function with incorrect parameter passing—typically when you omit parameters that other parameters depend on, or when parameters are declared but not provided in the correct order. This error prevents execution until parameters are properly aligned, and it’s common when migrating code, modifying stored procedures, or testing new queries. The fix generally requires checking parameter definitions against the execution call and ensuring all required parameters are included in the correct sequence.
What You'll Need
- A working SQL Server instance (local or cloud) with access to management tools (SSMS, T-SQL client, or query browser)
- The stored procedure or function that’s failing—either the stored procedure definition or a script containing it
- Your parameterized query or stored procedure call (the script producing the error)
- Basic SQL knowledge to read parameter declarations and syntax
Step-by-Step
- Identify the exact error in your query or stored procedure
- Open your query or stored procedure in your SQL client (e.g., SSMS, Azure Data Studio, or a T-SQL editor). Right-click the error message and select "Show Detailed Error" if the error is vague. Look for the line number and a description like "parameter mismatch" or "not enough parameters."
- If using SSMS, examine the error details in the "Errors" window. The error will often reference a specific parameter (e.g., "@param1" or "parameter index X").
- Check whether the error mentions "missing parameter" or "parameter not provided" to confirm the issue is parameter-related.
- Compare the stored procedure definition with your execution call
- Locate the stored procedure definition—either in the database object browser or via a `sp_helptext` query:
EXEC sp_helptext @objname = 'YourProcedureName'or in SSMS by right-clicking the procedure and selecting "Script Procedure As > Create To > NEWQUERY" - Write down the procedure signature (parameter list) from the definition. For example, a stored procedure might declare:
CREATE PROCEDURE dbo.GetUserData @UserID INT, @IncludeHidden BIT = 0 AS - Compare this signature with the parameters you’re passing in your execution call. For instance, your call might look like:
EXEC dbo.GetUserData 5, 1but the definition expects only @UserID (with @IncludeHidden as optional).
- Locate the stored procedure definition—either in the database object browser or via a `sp_helptext` query:
- Ensure parameters are in the correct order
- If the stored procedure expects parameters in a specific order (e.g., required followed by optional), verify your call matches this order. Some procedures use positional parameters, while others rely on named parameters (e.g., `@paramName = value`).
- For example, if the procedure definition requires:
@FirstName NVARCHAR(50), @LastName NVARCHAR(50)but your call isEXEC dbo.GetName 'John' 'Smith', the order is correct. If it wereEXEC dbo.GetName 'Smith' 'John', the error would occur because the first positional parameter (@FirstName) is missing.
- Check for missing parameters
- If the stored procedure requires a parameter (e.g., `@UserID` with no default value), ensure it’s included in your call. For example, the following call would fail:
EXEC dbo.GetUserDatabecause @UserID (and potentially @IncludeHidden) is missing. - Use the `sp_helptext` output or SSMS’s "View Procedure" tab to confirm which parameters are required (no defaults) and which are optional (with defaults).
- If the stored procedure requires a parameter (e.g., `@UserID` with no default value), ensure it’s included in your call. For example, the following call would fail:
- Modify your query or stored procedure call
- If the issue is missing parameters, add them to your call. For example, to call `GetUserData` properly:
EXEC dbo.GetUserData @UserID = 5, @IncludeHidden = 1 - If the issue is parameter order, reorder your parameters to match the stored procedure’s declaration. For named parameters, use explicit names:
EXEC dbo.GetUserData @UserID = 5, @IncludeHidden = 1 - If the stored procedure is being called from application code, ensure the developer is passing parameters in the correct sequence. For instance, in C# with Entity Framework, this would look like:
var result = dbContext.GetUserData(5, true);where the method signature is:IEnumerableGetUserData(int userId, bool includeHidden)
- If the issue is missing parameters, add them to your call. For example, to call `GetUserData` properly:
- Test the corrected query
- Execute the query or stored procedure again. If it’s a one-off query, run it directly in your T-SQL client. For stored procedures, use:
EXEC dbo.YourProcedureName @param1 = value1, @param2 = value2 - Check the results or the absence of errors in SSMS’s "Results" window. If no errors appear, the fix is likely correct.
- Execute the query or stored procedure again. If it’s a one-off query, run it directly in your T-SQL client. For stored procedures, use:
Common Mistakes
- Assuming optional parameters don’t need values: While optional parameters can omit their default value, if the procedure expects them to be set explicitly (e.g., via `EXEC` or application code), leaving them empty causes a mismatch. For example:
EXEC dbo.GetUserData @UserID = 5would work if @IncludeHidden had a default value like `0`, but it might fail if the application code requires explicit values. - Ignoring positional vs. named parameters: Some stored procedures rely on positional parameters (first parameter is always first), while others use named parameters (e.g., `@paramName = value`). If the procedure is ambiguous, always use named parameters to avoid confusion:
EXEC dbo.GetUserData @UserID = 5 @IncludeHidden = 1is clearer thanEXEC dbo.GetUserData 5, 1if the procedure might interpret the second `1` as a separate parameter. - Mismatched data types or values: Even if parameters are passed, their types (e.g., `INT`, `NVARCHAR`) or values (e.g., `NULL` vs. empty string) must align with the procedure’s expectations. For example, passing `0` instead of `NULL` for a nullable parameter could trigger an error if the procedure expects `NULL` explicitly.
- Caching or outdated definitions: If you’ve modified the stored procedure but haven’t refreshed your client’s cache, the definition might still show the old signature. Clear the SQL Server Object Explorer cache or restart SSMS to ensure you’re using the latest definition.
Tips
- Use parameter hints or shortcuts: In some cases, you can use SQL Server’s parameter hints to force the execution plan. For example:
EXEC dbo.GetUserData @UserID = 5 WITH RECOMPILEforces a new execution plan, which might resolve issues like parameter dependency conflicts. Use this sparingly after checking other solutions. - Document parameter usage: For frequently used stored procedures, document the correct parameter order and values. Store this in comments or a README file to avoid future errors.
- Check for deprecated parameters: If you’re migrating code, ensure no parameters are deprecated or removed from the stored procedure. Use `sp_helptext` or `EXEC sp_help @procedureName` to verify the current definition.
- Test in a staging environment: If you’re modifying a production procedure, test the changes in a staging database first. This ensures parameter passing works as expected before deploying to live systems.
- Use dynamic SQL cautiously: If you’re generating SQL dynamically (e.g., in application code), ensure the generated query includes all required parameters. For example:
DECLARE @sql NVARCHAR(MAX) = N'EXEC dbo.GetUserData ' + CAST(@UserID AS NVARCHAR) + ', ' + CAST(@IncludeHidden AS NVARCHAR);is risky if @IncludeHidden is optional and missing. Instead, explicitly include all parameters:DECLARE @sql NVARCHAR(MAX) = N'EXEC dbo.GetUserData @UserID = ' + CAST(@UserID AS NVARCHAR) + ', @IncludeHidden = ' + CAST(@IncludeHidden AS NVARCHAR);
Troubleshooting
- Error persists after parameter checks
- Verify the stored procedure exists and is accessible. Run:
SELECT * FROM INFORMATION_SCHEMA.ROUTINE_NAMES WHERE ROUTINE_NAME = 'YourProcedureName'to confirm it exists in the database. - Check for schema ownership. If the procedure belongs to another schema, qualify it:
EXEC dbo.GetUserData @UserID = 5might fail if the schema isn’t in the current context. Use:EXEC schema_name.dbo.GetUserData @UserID = 5to specify the schema.
- Verify the stored procedure exists and is accessible. Run:
- Parameters are correct but still failing
- Check for hidden or implicit parameters. Some procedures use temporary tables or output parameters that aren’t declared in the public interface. Review the full procedure definition for any hidden variables or `OUTPUT` parameters.
- Enable tracing to capture detailed error information:
EXEC sp_trace_create @trace_id = 1, @is_circular_log = 0, @file_name = N'C:\ErrorTrace.trc'Then run the failing command, and review the trace file for deeper clues.
- Application code errors
- If the error occurs in application code (e.g., C#, Python, or Java), check the parameter binding logic. For example, in C# with Entity Framework Core:
var result = context.GetUserData(userId, includeHidden);must match the procedure signature. If the procedure expects named parameters, bind them explicitly:var result = context.GetUserData(userId, includeHidden: true); - Log the actual parameters being passed. For example, in .NET:
Debug.WriteLine($"Called with: UserID={userId}, IncludeHidden={includeHidden}");to verify the values match the procedure’s expectations.
- If the error occurs in application code (e.g., C#, Python, or Java), check the parameter binding logic. For example, in C# with Entity Framework Core:
- SQL Server service or permissions
- Ensure the SQL Server service is running. Restart the SQL Server service if it’s stalled:
net stop sqlserver /y; net start sqlserver(Windows) or check the service manager on Linux/macOS. - Verify your user has execute permissions on the procedure. Run:
GRANT EXECUTE ON dbo.GetUserData TO YourUserif needed.
- Ensure the SQL Server service is running. Restart the SQL Server service if it’s stalled:
Frequently Asked Questions
Why does SQL Server Error 119 occur even if I provided all parameters?
If all parameters are provided but the error persists, the issue might be:
- The procedure expects a specific order of parameters (e.g., positional parameters first), and you’re passing them in the wrong sequence.
- There are hidden or output parameters not exposed in the public interface (e.g., temporary variables or `OUTPUT` parameters).
- The call is missing parameters that are technically implicit (e.g., session variables or transaction scopes).
Solution: Inspect the full procedure definition to confirm the expected parameter order and any hidden dependencies.
Can I force SQL Server to ignore parameter order errors?
No, SQL Server enforces parameter passing strictly. However, you can use parameter hints like `WITH RECOMPILE` or named parameters (e.g., `@paramName = value`) to bypass some issues, but this isn’t a permanent solution. Always fix the root cause by aligning the call with the procedure’s definition.
What if I’m calling a stored procedure from a script and it fails with Error 119?
If the failure is script-based (e.g., a PowerShell or bash script), ensure:
- The script uses explicit parameter names or positional arguments that match the procedure’s declaration.
- Quoting is correct—for example, use single quotes for strings:
EXEC dbo.GetUserData @UserID = '5'instead of:EXEC dbo.GetUserData '5'(the latter treats `5` as a literal string). - The script is not mixing dynamic SQL with manual parameters (e.g., concatenating values with string literals).
Test the script in a T-SQL client first to isolate the issue.
How do I know if a parameter is optional in SQL Server?
Check the stored procedure definition for these clues:
- Parameters with a default value (e.g., `@IncludeHidden = 0`) are optional if not provided explicitly.
- In the definition, look for `OUTPUT`, `IN OUT`, or `OUTPUT` keyword usage (these are not optional).
- Use `sp_helptext` to inspect the full procedure:
EXEC sp_helptext 'dbo.GetUserData'and search for `@paramName = default_value` to identify optional parameters.
However, even optional parameters may require explicit values in application code or dynamic SQL.
I’ve fixed the parameters but the error still appears—what else could it be?
Other causes include:
- Transaction scope issues: If the call is inside a transaction, parameters might be tied to session state. Commit or rollback the transaction before retrying.
- Schema or collation mismatches: Ensure the schema where the procedure exists matches the one you’re calling from, and collations (e.g., `SQL_Latin1_General_CP1_CI_AS`) are compatible.
- Caching problems: Clear the SQL Server Object Explorer cache or restart SSMS to refresh the procedure’s definition.
- Dependency on other objects: The procedure might rely on tables, views, or other objects that are missing or incorrectly referenced.
Use `sp_who2` or `SET SHOWPLAN_TEXT ON` to diagnose execution plans and identify hidden issues.
How can I prevent SQL Server Error 119 in the future?
To avoid this issue, adopt these practices:
- Document parameter usage for each stored procedure, including required/optional parameters and their order.
- Use named parameters (e.g., `@paramName = value`) in application code to avoid positional errors.
- Test parameter calls in a staging environment before deploying to production.
- Avoid dynamic SQL without explicit parameter validation. For example:
DECLARE @sql NVARCHAR(MAX) = 'SELECT * FROM Table WHERE Column = @value'; EXEC sp_executesql @sql, N'@value INT', @value = 1;instead of:DECLARE @sql NVARCHAR(MAX) = 'SELECT * FROM Table WHERE Column = ' + CAST(1 AS NVARCHAR)(the latter is unsafe and prone to errors). - Enable SQL Server auditing or logging for stored procedure calls to track parameter usage over time.