Skip to content

Commit 03469e6

Browse files
authored
Merge pull request #8638 from MicrosoftDocs/OOM_SSMS_pijocoder_040225
AB#5318: Update Title and cause with OOM message, also applies to SSMS not SQL Server
2 parents a15da25 + 6d830e9 commit 03469e6

1 file changed

Lines changed: 7 additions & 36 deletions

File tree

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
2-
title: Exception when you execute a query
2+
title: OutOfMemoryException Error When You Execute a Query
33
description: This article provides workarounds for the problem that occurs when you use SQL Server Management Studio (SSMS) to run a SQL query that returns a large amount of data.
4-
ms.date: 10/29/2020
4+
ms.date: 04/08/2025
55
ms.custom: sap:SQL Server Management, Query and Data Tools
6+
ms.reviewer: jopilov
67
---
7-
# Exception when you execute a query in SQL Server Management Studio
8+
# OutOfMemoryException error when you execute a query in SQL Server Management Studio (SSMS)
89

910
This article helps you resolve the problem that occurs when you use SQL Server Management Studio (SSMS) to run a SQL query that returns a large amount of data.
1011

@@ -13,16 +14,13 @@ _Original KB number:_   2874903
1314

1415
## Symptoms
1516

16-
When you use SSMS to run a SQL query that returns a large amount of data, you receive an error message that resembles the following:
17+
When you use SSMS to run a SQL query that returns a very large amount of data, you receive an error message that resembles the following:
1718

1819
> An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown
1920
2021
## Cause
2122

22-
This issue occurs because SSMS has insufficient memory to allocate for large results.
23-
24-
> [!NOTE]
25-
> SSMS is a 32-bit process. Therefore, it is limited to 2 GB of memory. SSMS imposes an artificial limit on how much text that can be displayed per database field in the results window. This limit is 64 KB in "Grid" mode and 8 KB in Text mode. If the result set is too large, the memory that is required to display the query results may surpass the 2 GB limit of the SSMS process. Therefore, a large result set can cause the error that is mentioned in the [Symptoms](#symptoms) section.
23+
This issue occurs because SSMS has insufficient memory to allocate for large results. SSMS is a 32-bit process. Therefore, it's limited to 2 GB of user-mode virtual memory. SSMS imposes an artificial limit on how much text can be displayed per database field in the results window. This limit is 64 KB in Grid mode and 8 KB in Text mode. If the result set is too large, the memory that is required to display the query results may surpass the 2 GB limit of the SSMS process. Therefore, a large result set can cause the error that is mentioned in the [Symptoms](#symptoms) section.
2624

2725
## Workaround
2826

@@ -47,31 +45,4 @@ Configure the query window to output the query results to a file. A file output
4745

4846
## Method 3: Use sqlcmd
4947

50-
Use [sqlcmd Utility](/sql/tools/sqlcmd-utility?redirectedfrom=MSDN&view=sql-server-ver15&preserve-view=true) instead of SSMS to run the SQL queries. This method enables queries to be run without the resources that are required by the SSMS UI. Additionally, you can use the 64-bit version of Sqlcmd.exe to avoid the memory restriction that affects the 32-bit SSMS process.
51-
52-
## Applies to
53-
54-
- SQL Server 2012 Express
55-
- SQL Server 2012 Developer
56-
- SQL Server 2012 Enterprise
57-
- SQL Server 2012 Standard
58-
- SQL Server 2012 Web
59-
- SQL Server 2008 R2 Datacenter
60-
- SQL Server 2008 R2 Developer
61-
- SQL Server 2008 R2 Enterprise
62-
- SQL Server 2008 R2 Express
63-
- SQL Server 2008 R2 Standard
64-
- SQL Server 2008 R2 Web
65-
- SQL Server 2008 R2 Workgroup
66-
- SQL Server 2008 Developer
67-
- SQL Server 2008 Enterprise
68-
- SQL Server 2008 Express
69-
- SQL Server 2008 Standard
70-
- SQL Server 2008 Web
71-
- SQL Server 2008 Workgroup
72-
- SQL Server 2005 Developer Edition
73-
- SQL Server 2005 Enterprise Edition
74-
- SQL Server 2005 Evaluation Edition
75-
- SQL Server 2005 Express Edition
76-
- SQL Server 2005 Standard Edition
77-
- SQL Server 2005 Workgroup Edition
48+
Use [sqlcmd Utility](/sql/tools/sqlcmd/sqlcmd-utility) instead of SSMS to run the SQL queries. This method enables queries to be run without the resources that are required by the SSMS UI. Additionally, you can use the 64-bit version of Sqlcmd.exe to avoid the memory restriction that affects the 32-bit SSMS process.

0 commit comments

Comments
 (0)