Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 349 Fixed Fast

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The SQL Server error 349 (procedure has no parameter named) almost always means you’re calling a stored procedure with the wrong parameter list. The fix is simple: check your syntax for typos, missing parameters, or mismatched names between the definition and your call. Most cases resolve in under a minute by verifying parameter order and data types. If the procedure is dynamic SQL, ensure the variable names in your EXEC or SP_EXECUTESQL match the parameter list.

What You'll Need

  • A SQL Server Management Studio (SSMS) or query tool with schema access (Azure Data Studio, Visual Studio, or client tools).
  • The exact stored procedure name and its source code (or permissions to view it).
  • Admin privileges or a DDL script to inspect the procedure (if you can’t view it directly).
  • If using dynamic SQL, the raw EXECUTE or SP_EXECUTESQL statement causing the error.

Step-by-Step

  1. Identify the problematic call. Locate the exact line where error 349 occurs. In SSMS, hover over the red underline or check the execution plan for the query with the error. For dynamic SQL, note the SP_EXECUTESQL or EXEC statement that includes the procedure name.
  2. Verify the procedure definition. Open the stored procedure in SSMS by:
    1. Right-clicking the procedure in Object Explorer > Modify (or Script Procedure as > CREATE To > New Query Editor Window if the Modify option is disabled).
    2. Reviewing the parameter list for exact names, data types, and order. Example:
      CREATE PROCEDURE dbo.GetCustomer(@CustomerID int, @Name NVARCHAR(100))
      Here, `@CustomerID` is the first parameter, and `@Name` is the second.
  3. Match the procedure call to the definition. Compare the call to the parameter list. Common mistakes:
    • Wrong parameter count: Calling EXEC GetCustomer @CustomerID when the procedure expects two parameters.
    • Wrong parameter order: Writing EXEC GetCustomer @Name = 'John', @CustomerID = 123 when `@CustomerID` should be first.
    • Mismatched types: Passing a string where an INT is required (e.g., @CustomerID = 'abc').
    • Typo in parameter names: Using @CustID instead of @CustomerID. Partial matches (like `@C` for `@Customer`) won’t work.
  4. Fix the call. Update your query or script to match the definition:
    • Add missing parameters (include defaults if they exist).
    • Reorder parameters to match the definition (or use named parameters).
    • Correct data types (e.g., cast a string to an INT with CONVERT(int, @param)).
    • Verify exact spelling and case sensitivity (SQL Server is case-insensitive for identifiers by default, but some collations treat it as case-sensitive).
  5. Test the corrected call. Run the procedure again with your fixed syntax. If it still fails:
    1. Check for hidden characters (e.g., trailing spaces in parameter names). Use SELECT @CustomerID = 'Test' COLLATE SQL_Latin1_General_CP1_CI_AS to expose whitespace.
    2. Verify no intermediate variables or dynamic SQL are altering the parameter names.
  6. (Optional) Recreate the procedure if needed. If the procedure is corrupted or you lack edit permissions, recreate it:
    DROP PROCEDURE dbo.GetCustomer;
    GO
    CREATE PROCEDURE dbo.GetCustomer @CustomerID int, @Name NVARCHAR(100) AS
        SELECT * FROM Customers WHERE CustomerID = @CustomerID AND Name = @Name;
    GO

Common Mistakes

Error 349 often stems from these pitfalls:

  • Assuming optional parameters work like functions. SQL Server doesn’t skip parameters unless explicitly defined with DEFAULT values. Example:
    CREATE PROCEDURE dbo.ReportSales @StartDate DATE = GETDATE() -- Valid
            EXEC ReportSales '2023-01-01' -- Error if @StartDate is omitted unless it has a DEFAULT.
  • Dynamic SQL with hardcoded parameter names. If you use SP_EXECUTESQL, the parameter names in the dynamic SQL must exactly match the declared variables. Example:
    DECLARE @Name NVARCHAR(100) = 'John';
    EXEC SP_EXECUTESQL N'SELECT * FROM Customers WHERE Name = ?', N'@Name NVARCHAR(100)', @Name;
  • Partial parameter names. SQL Server won’t auto-complete partial names. @Cust won’t match @CustomerID.
  • Ignoring table/column names in error messages. The error may list the procedure name but point to a specific line in complex queries. Use SET SHOWPLAN_TEXT ON to debug.

Tips

  • Use named parameters consistently. Writing EXEC GetCustomer @CustomerID = 123, @Name = 'John' makes the order irrelevant and reduces errors.
  • Leverage SSMS IntelliSense. After typing EXEC , press Ctrl+Space to see available parameters and their data types.
  • Check for implicit conversions. If your call works but throws 349 in another environment (e.g., production), test for type mismatches with SELECT CAST(@param AS type).
  • Document parameter lists. Add comments to procedures for clarity:
    CREATE PROCEDURE dbo.TransferFunds
        @FromAccount INT,    -- Sender account ID
        @ToAccount INT,      -- Recipient account ID
        @Amount DECIMAL(18,2) -- Transfer amount (must be positive)
  • Test in a sandbox first. If you’re unsure, recreate the procedure in a test database and verify calls there before deploying to production.

Troubleshooting

If your fix doesn’t resolve error 349, follow this order:

1. Restart SQL Server and your client tool.

Sometimes cached execution plans or tool glitches cause false errors. Restart the SQL Server instance (via Services on Windows or System Preferences on macOS) and reopen your query tool.

2. Check for schema or permission issues.

Error 349 can mimic permission errors if you lack EXECUTE permissions on the procedure. Verify with:

SELECT HAS_PERMS_BY_NAME('dbo.GetCustomer', 'OBJECT', 'EXECUTE') AS CanExecute;
If it returns 0, ask your DBA for permissions or recreate the procedure in your schema.

3. Inspect dynamic SQL carefully.

If the procedure uses dynamic SQL (e.g., via sp_executesql), the error might stem from:

  • Mismatched variable names between the script and the EXEC call.
  • Hardcoded parameter names in the dynamic SQL that don’t align with the caller’s variables.
Use PRINT statements to log the exact dynamic SQL being executed:
DECLARE @SQL NVARCHAR(MAX) = N'SELECT * FROM Customers WHERE Name = ''' + @Name + '''';
PRINT @SQL; -- Verify this is what’s actually running
EXEC sp_executesql @SQL;

4. Compare definitions across environments.

If the procedure works in one database but fails in another, the definitions might differ. Use:

SELECT DEFINITION FROM sys.sql_modules WHERE OBJECT_ID = OBJECT_ID('dbo.GetCustomer');
Compare the output between environments.

5. Enable extended events or trace for deeper insights.

For persistent issues, capture errors with:

CREATE EVENT SESSION [Procedures] ON SERVER
ADD EVENT sqlserver.error_reports
ADD TARGET package0.event_file(SET filename=N'Procedures');
Then run ALTER EVENT SESSION [Procedures] ON SERVER STATE = START; and check the logs in C:\Program Files\Microsoft SQL Server\Log\.

6. Last resort: Rebuild the procedure.

If all else fails, recreate the procedure from scratch using the most recent source control version or a trusted backup. This ensures no hidden corruption.

Frequently Asked Questions

Why does error 349 happen even when my parameter names match?

The most likely causes are:

  • The procedure definition includes OPTION (RECOMPILE) or WITH RECOMPILE, forcing a fresh parse that might not see your changes.
  • A cached plan is using an outdated procedure definition. Clear plans with DBCC FREEPRO procedures or restart SQL Server.
  • The parameter name in the call is case-sensitive in your collation (unlikely unless you’re using a custom collation like SQL_Latin1_General_CP1_CS_AS).

Can I use wildcards (e.g., @C*) in parameter names?

No. SQL Server does not support partial parameter name matching. Wildcards like @C* or @Id for @CustomerID will always fail with error 349. Always use the exact parameter name.

How do I debug dynamic SQL that throws error 349?

Break the dynamic SQL into steps:

  1. Print the final SQL string before execution to verify parameter interpolation worked:
    DECLARE @SQL NVARCHAR(MAX) = N'SELECT * FROM Customers WHERE Id = ' + CAST(@Id AS NVARCHAR(20));
    PRINT @SQL;
  2. Check if the printed SQL matches what you intended. If not, fix the string concatenation.
  3. Use EXEC sp_executesql @SQL, N'@Id INT', @Id; to ensure parameter declarations align.

Does error 349 occur with functions instead of procedures?

No. Error 349 is specific to stored procedures and dynamic SQL. Functions use different error codes (e.g., 512 for incorrect number of arguments). If you see this error with a function, you’re likely calling it wrong (e.g., passing arguments in the wrong order).

Why does my procedure work in SSMS but fail when called from an application?

Check these application-specific issues:

  • Parameter binding order: Some ORMs (like Entity Framework) bind parameters by position, not name. Ensure your application’s call matches the procedure’s parameter order.
  • Data type mismatches in the client: The application might be sending a different type than expected (e.g., sending a decimal as a float). Log the actual values being passed.
  • Transaction scope: If the application wraps the call in a transaction, error handling might mask the 349 code. Use SET XACT_ABORT ON; in the procedure to force failures.
Test the call directly from the application’s connection string to isolate the issue.

How can I find all procedures with this error in my database?

Use this script to generate a list of procedures that might be causing parameter mismatches:

SELECT
    s.name AS schema_name,
    o.name AS object_name,
    m.definition
FROM
    sys.sql_modules m
INNER JOIN
    sys.objects o ON m.object_id = o.object_id
INNER JOIN
    sys.schemas s ON o.schema_id = s.schema_id
WHERE
    o.type = 'P' -- Procedures only
    AND m.definition LIKE '%@%' -- Likely uses parameters
ORDER BY
    o.name;
Then review each procedure’s definition to verify parameter usage.