Data factory fails to run Stored Procedure when SSMS succeeds

Lun, Biondi 0 Reputation points
2025-06-04T21:24:52.7533333+00:00

I have a nightly job that generates an email via a stored procedure run through azure data factory. It has been in use for about 2 years with no problem. Yesterday it failed without any changes to the SQL

A database operation failed with the following error: 'The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.'
The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information., SqlErrorNumber=8623,Class=16,State=1,

I was able to run the same stored procedure in MSSMS with no issues and I've looked through query analyzer and there were no outstanding issues with performance.

Any idea what's going on?

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2025-06-04T22:05:37.1633333+00:00

    I'm very short on time right now, but try this in SSMS:

    SET ARITHABORT OFF
    EXEC YourSP
    

    You may get the same error.

    I guess the reason the query started to fail is that statistics have changed, which caused SQL Server to recompile the query, and then took a different route during optimization.

    If this is Azure SQL Database, automatic indexing may also cause you surprises.

    In any case, try to identify the problematic query and try to simplify it, for instance by introducing an intermediate temp table or two.

    1 person found this answer helpful.

  2. PratikLad 1,825 Reputation points Microsoft External Staff Moderator
    2025-06-16T16:48:59.6733333+00:00

    Hi Lun, Biondi

    Glad to know Biondi Lun you have solved it. I am collating the data in one place for anyone in the QnA forum to refer to it

    Adding to @Erland Sommarskog answer, this error happens at the Query Execution Process. This error is not related to a particular area of code. Sometimes when the query execution is taking more time in the query engine, the process could be suspended and an error raised, which means the query processor has limitations and it doesn’t produce a query plan.

    Some workarounds to resolve this:

    • First, verify server and database level configurations and resource availability (memory, CPU, etc.) as well.
    • Try to simplify the query rather than deal with a very complex query. If possible, re-write the query and removed unnecessary joins, unions, complex subqueries, conditions, etc.
    • Try to update indexes and statistics because the problem might be due to outdated statistics.

    If this answers your query, do click Accept Answer and Upvote for was this answer helpful.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.