3

We updated Entity Framework to 6.1.3, since then on some servers (sadly the ones that run the unit tests), we get now the exception:

System.Data.SqlClient.SqlException: Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.

on some EF queries that aren't that deep nested.

When we changed EF versions we made other changes, but none of these seem to have influenced the unit tests. The service that uses these queries wasn't changed at all.

I didn't find any condition in the environment for this exception, and I kinda can't believe it happens because of the EF update. Are there more influences that could cause this exception?

Edit: I just extracted the query and ran it on one of the failing servers, which is working funnily enough. So I guess it has to be EF?

Kit
  • 20,354
  • 4
  • 60
  • 103
Matthias Müller
  • 3,336
  • 3
  • 33
  • 65
  • What did you update from? What does you SQL statement look like? – ErikEJ Jul 01 '15 at 08:05
  • Does all your sql server has exactly the same version ? use `Select @@Version` to check the version. – Cyril Durand Jul 01 '15 at 08:20
  • Updated the Question, or is it still relevant, which Statement / SQL Version it is? – Matthias Müller Jul 01 '15 at 09:00
  • We had the same issue and it was fixed by applying update on SQL Server. See https://connect.microsoft.com/SQLServer/feedback/details/805659/sql-statement-is-nested-too-deeply – Cyril Durand Jul 01 '15 at 09:04
  • Can you probably tell me from which version to which version you updated? This would help me a lot. – Matthias Müller Jul 01 '15 at 09:18
  • I don't remember but it seems that it have been corrected with SQL Server 2012 SP2 (https://support.microsoft.com/en-us/kb/2958429) and SQL Server 2014 SP1 (https://support.microsoft.com/en-us/kb/3058865) – Cyril Durand Jul 01 '15 at 09:23
  • Many thanks, I will update one Build-Server to the same Version I have locally and check if this causes the Problem. It's quite strange nobody else has this problems. – Matthias Müller Jul 01 '15 at 09:57
  • Hey Cyril, worked perfectly, thanks. If you mark your Comment as answer, I will mark it. Interesting enough, it seems like a Combination of SQL and Entity Framework. – Matthias Müller Jul 01 '15 at 11:54
  • **Related post** - [Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries](https://stackoverflow.com/q/14163390/465053) – RBT Apr 09 '18 at 11:29

1 Answers1

5

Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.

This error message is generated by SQL Server. It indicates that a SQL query can't be analyzed because it is too complex. The new version of Entity Framework you used may have a different optimizer that will generate a more nested SQL query than before, this is why you have this error message now.

This error message may also happens on some version of SQL Server. If your SQL Servers don't have the same version, it could explain why you reproduce it only on some configuration. You can find more information on this behavior in this connect bug : SQL statement is nested too deeply

This issue has been fixed with SQL Server 2012 SP2 and SQL Server 2014 SP1

Cyril Durand
  • 15,834
  • 5
  • 54
  • 62