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

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 121.3K 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.


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.