Error 155 in SQL Server typically means you’ve used an unsupported option, invalid syntax, or a parameter that doesn’t match your query type. This happens most often when using stored procedures, dynamic SQL, or parameterized queries incorrectly. The fix is to either remove the unsupported option, check your query’s parameter compatibility, or rewrite it with valid SQL syntax.

What You'll Need

  • SQL Server Management Studio (SSMS), Query Analyzer, or a compatible SQL client
  • Access to your SQL Server instance (local or remote)
  • Basic knowledge of SQL syntax and stored procedures (if applicable)

Step-by-Step

  1. Review the exact error message Error 155 usually includes a hint like "Invalid option" or "Parameter not recognized." Open your query in a tool like SSMS, paste the error, and check the full stack trace to identify which parameter or keyword is invalid.
  2. Check for unsupported SQL Server features If using older SQL Server versions (pre-2016), some parameters or syntax may be missing. For example:
    • "@output" parameters require SQL Server 2012 or later.
    • Some dynamic SQL constructs (e.g., `sp_executesql`) may need validation against your version.
    Upgrade if possible, or use alternative syntax (e.g., `EXECUTE AS` instead of `@output`).
  3. Verify parameter types and values If error 155 arises from a stored procedure, ensure parameters match their declared data types (e.g., `INT`, `NVARCHAR`, `DATE`). For example:
        -- Invalid (mismatch): Passing a string where an INT is expected
        EXEC usp_UpdateCustomer @Name = 'John'; -- Error 155 if @Name is defined as INT
        
    Correct it by casting or redefining the parameter:
        EXEC usp_UpdateCustomer @Name = CAST('John' AS INT); -- Only if logic allows
        
  4. Rewrite dynamic SQL with static queries If using `sp_executesql` with invalid SQL strings, strip the problematic syntax. For example:
        -- Problematic (error 155 if SQL syntax is invalid)
        DECLARE @sql NVARCHAR(MAX) = 'SELECT * FROM Table WHERE InvalidKeyword = @p1';
        EXEC sp_executesql @sql, N'@p1 VARCHAR(100)', @p1 = 'Test';
        
    Replace with a validated query:
        EXECUTE('SELECT * FROM Table WHERE Id = @p1', N'@p1 INT', @p1 = 1);
        
  5. Update or reinstall SQL Server If the issue persists after checking syntax, SQL Server might be corrupted. Run:
    1. Repaire the SQL Server installation via "Add or Remove Programs."
    2. Restart SQL Server Service (Services.msc).

Common Mistakes

  • Mixing SQL Server versions – Using `NEWID()` in SQL Server 2016+ but passing it to an older procedure.
  • Ignoring nullability – Passing `NULL` where a non-nullable parameter is required.
  • Overusing dynamic SQL – Letting strings include invalid SQL constructs (e.g., `DROP TABLE` in a query).
  • Copy-pasting queries – Assuming all stored procedures are compatible across editions (e.g., Express vs. Enterprise).

Tips

  • Use `TRY/CATCH` blocks to gracefully handle errors like 155 without stopping execution.
  • Query the system catalog to check for deprecated functions:
        SELECT name, definition FROM sys.sql_modules WHERE definition LIKE '%deprecated%';
        
  • For stored procedures, redeclare parameters if you suspect a version mismatch:
        ALTER PROCEDURE usp_UpdateOldStyle
        @Name INT -- Force INT instead of VARCHAR
        AS ...
        
  • If error 155 occurs in a script, use `OPTION (RECOMPILE)` to bypass some version quirks.

Troubleshooting

If the error persists after basic checks:

  1. Check the SQL Server error log Navigate to `\Log` and look for entries around the time of failure. Logs often include the exact query causing the issue.
  2. Test in a fresh session Open a new SSMS connection and run the query again. Corrupted sessions can trigger this error.
  3. Verify the SQL Agent job (if applicable) If error 155 appears in scheduled queries, check the job step for failed steps or invalid parameters.
  4. Contact support if the issue involves a custom OLE DB provider Some third-party connectors may not support all SQL Server features.

Frequently Asked Questions

Why does SQL Server error 155 keep happening in the same query?

This often means your query contains deprecated syntax, a version mismatch (e.g., using `100` instead of `100.0`), or a parameter value that conflicts with the procedure’s schema. Review the procedure’s definition and parameter types carefully.

How can I find out which parameter is causing error 155?

Use `sp_trace` or enable SQL Server error logging. Alternatively, replace each parameter one by one with `ISNULL()` or a default value to isolate the culprit.

What if I’m using SQL Server 2012 and error 155 appears with `OUTPUT` clauses?

SQL Server 2012 introduced `@output` parameters, but some older tools may not support them. Replace with standard `RETURN` clauses or upgrade to a newer version.

Does error 155 always relate to parameters?

No. It can also occur if you’re using reserved keywords (e.g., `SELECT` as a variable name) or invalid syntax in dynamic SQL. Check the full error message for context.

How do I prevent this in future queries?

Use static queries for critical operations, validate parameters against your schema, and avoid dynamic SQL unless absolutely necessary. Tools like SSMS’s "Show Plan" can also help detect potential issues early.

What if the error is linked to a third-party OLE DB provider?

Contact the provider’s support team or update their driver to a compatible version. Avoid mixing incompatible drivers in the same connection pool.

If none of these steps resolve the issue, consider contacting Microsoft Support with the exact error message, query, and SQL Server version for deeper analysis.