%3CLINGO-SUB%20id%3D%22lingo-sub-1564815%22%20slang%3D%22en-US%22%3EInvalid%20operation.%20The%20connection%20is%20closed%20or%20Query%20too%20complex%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1564815%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EScenario%3C%2FSTRONG%3E%3A%20When%20executed%20more%20than%20325%20columns%20in%20a%20select%20query%20the%20error%20bellow%20was%20thrown%3A%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%5B110813%5D%20Invalid%20operation.%20The%20connection%20is%20closed.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20same%20query%20with%20fewer%20columns%20than%20that%20worked.%20So%20it%20seems%20it%20was%20hitting%20some%20kind%20of%20limit.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20we%20got%20the%20request%20after%20some%20troubleshooting%20we%20found%20the%20following%20error%20on%20the%20logs%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3EThe%20service%20has%20encountered%20an%20error%20processing%20your%20request.%20Please%20try%20again.%20Error%20code%208632.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20it%20was%20not%20a%20matter%20of%20hard%20limit%2C%20but%20complexity%20and%20translation%20that%20may%20happen%20in%20any%20version%20of%20SQL%20Server.%3C%2FP%3E%0A%3CP%3EI%20know%20this%20doc%20is%20SQL%20Server%202005%2C%20but%20the%20issue%20is%20the%20same.%20When%20the%20query%20is%20too%20complex%20it%20must%20be%20simplified.%20So%20SQL%20does%20not%20map%20de%20number%20of%20expressions%20directly.%26nbsp%3B%20Using%26nbsp%3B%20the%20doc%20words%3A%3C%2FP%3E%0A%3CP%3E%22%3CEM%3EThis%20issue%20occurs%20because%20SQL%20Server%20limits%20the%20number%20of%20identifiers%20and%20constants%20that%20can%20be%20contained%20in%20a%20single%20expression%20of%20a%20query.%20This%20limit%20is%2065%2C535.%20For%20example%2C%20the%20following%20query%20only%20has%20one%20expression%3A%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eselect%20a%2C%20b%20%2B%20c%2C%20d%20%2B%20e%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3EThis%20expression%20retrieves%20all%20five%20columns%2C%20calculates%20the%20addition%20operators%2C%20and%20sends%20three%20projected%20results%20to%20the%20client.%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fprotect2.fireeye.com%2Fv1%2Furl%3Fk%3D72012348-2ca19926-7201cd07-869a14f4b08c-438b66f6671c400c%26amp%3Bq%3D1%26amp%3Be%3Dc0122a21-6923-4ad0-bd93-302af91d20c4%26amp%3Bu%3Dhttps%253A%252F%252Fsupport.microsoft.com%252Fen-us%252Fhelp%252F913050%252Ferror-message-when-you-run-a-query-in-sql-server-2005-internal-error-a%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F913050%2Ferror-message-when-you-run-a-query-in-sql-server-2005-internal-error-a%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20solution%20was%20simplified%20the%20query%20text.%20Some%20functions%20were%20added%20on%20Select%20statement%2C%20SQL%20query%20text%20was%20simplified%20and%20the%20query%20worked%20after%20that.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20is%20it!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELiliam%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUK%20Engineer%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1564815%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EScenario%3C%2FSTRONG%3E%3A%20When%20executed%20more%20than%20325%20columns%20in%20a%20select%20query%20the%20error%20bellow%20was%20thrown%3A%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3E%5B110813%5D%20Invalid%20operation.%20The%20connection%20is%20closed.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20same%20query%20with%20fewer%20columns%20than%20that%20worked.%20So%20it%20seems%20it%20was%20hitting%20some%20kind%20of%20limit.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1564815%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EInternals%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESynapse%20SQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Scenario: When executed more than 325 columns in a select query the error bellow was thrown:

[110813] Invalid operation. The connection is closed.

 

The same query with fewer columns than that worked. So it seems it was hitting some kind of limit.

 

Once we got the request after some troubleshooting we found the following error on the logs: 

The service has encountered an error processing your request. Please try again. Error code 8632.

 

So it was not a matter of hard limit, but complexity and translation that may happen in any version of SQL Server.

I know this doc is SQL Server 2005, but the issue is the same. When the query is too complex it must be simplified. So SQL does not map de number of expressions directly.  Using  the doc words:

"This issue occurs because SQL Server limits the number of identifiers and constants that can be contained in a single expression of a query. This limit is 65,535. For example, the following query only has one expression:

select a, b + c, d + e

This expression retrieves all five columns, calculates the addition operators, and sends three projected results to the client."

https://support.microsoft.com/en-us/help/913050/error-message-when-you-run-a-query-in-sql-server-200...

 

 

The solution was simplified the query text. Some functions were added on Select statement, SQL query text was simplified and the query worked after that.

 

That is it!

 

Liliam 

UK Engineer