Error 8632: Internal Error, Expression Services Limit Reached

Error 8632 is the internal error that says an expression services limit has been reached. I met it while helping a client with a Comprehensive Database Performance Health Check. A few of their stored procedures failed with it.

Gouache painting of a large tangled and knotted ball of cream cord on a wooden table, one strand of it vermilion

The Error

Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.

What the Client Saw

After a SQL Server upgrade, the client had a query performance regression. A few queries and stored procedures weren’t performing well. During the investigation, we found a few queries that gave the error above.

One of the first reactions was to restart SQL Server. That wasn’t possible, because the business needed continuity. I also don’t see a point in a restart unless there are major configuration changes or patch upgrades.

Why It Happens

I made a copy of each stored procedure, and every copy worked fine. That told me the error was not tied to the query text. It was tied to the cached stored procedures.

Gouache painting of a neatly coiled cream rope on a wooden table, one vermilion strand lying straight

The Fix

The solution was simple. We opened each stored procedure and recreated it with the same name, and everything worked. Some procedures had other stored procedures inside them. We recreated or recompiled the nested ones too, and the error went away.

This command recompiles a stored procedure:

EXEC sp_recompile N'SPName';
GO

How to Prevent It

After an upgrade, try a recompile before you reach for a restart. If you’ve faced this error, please tell me in the comments how you fixed it.

Quick reference card: Error 8632: Expression Limit

Error 8632 is not a query to rewrite, it is a cached procedure to refresh.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Recompile, SQL Error Messages, SQL Stored Procedure, SQL Upgrade
Previous Post
Check Constraint on Identity Column: Why Inserts Fail
Next Post
Rewriting Correlated Subqueries as Window Functions

Related Posts

6 Comments. Leave new

  • What version of SQL was throwing this error?

    Reply
  • We are getting this error for queries in windows application. We don’t use stored procedures. What do you suggest?

    Reply
  • trevormorehead2015
    May 8, 2021 7:03 pm

    I found these work arounds:

    ALTER DATABASE SCOPED CONFIGURATION SET TSQL_SCALAR_UDF_INLINING = OFF;

    Less desirable workaround:
    Use SQL 2017 compatibility mode

    Reply
  • Hi,
    I got this error in sqlserver 2019. My database migrated from sql 2017. I have got 4 databases and these databases access to another via views etc. 3 databases compatibility level were 2012 and main database compatibility level was 2019 (I don’t known why. its’ mistake). I changed main database compatibility level from 2019 to 2017 then errors gone. After that I changed all databases compatibility level to 2019 (150) and errors gone. May be issue related with this.

    Reply
  • Tank you , Tank You very very much

    Reply
  • Kaushal Parekh
    June 28, 2023 7:37 pm

    trevormorehead2015 thank you so much. That work around command fix the thing.

    why did you mentioned “less desirable”?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.