Troubleshooting Guide: Error 10769 – “SET Options Are Not Supported Inside ATOMIC Blocks”
Why This Error Happens
This error occurs when a natively compiled stored procedure or module containing an ATOMIC block attempts to execute a SET statement (such as SET NOCOUNT, SET ANSI_WARNINGS, or SET DATEFORMAT) that is explicitly disallowed within the atomic execution context. SQL Server’s natively compiled modules require a fixed set of session options determined entirely at compile time via the WITH clause of the BEGIN ATOMIC statement, rather than being altered dynamically at runtime. This typically results from legacy T-SQL code or migration scripts that were written for interpreted Transact-SQL and have not been properly adapted for memory-optimized, natively compiled procedures in SQL Server 2025.
Step-by-Step Resolution Guide
Step 1: Identify the Offending SET Statement
- Open the stored procedure or function definition using SQL Server Management Studio (SSMS) or Azure Data Studio.
- Locate the
CREATE PROCEDUREorCREATE FUNCTIONdefinition and scan the body for anySETkeyword occurring after theBEGIN ATOMICdeclaration. - Common culprits include
SET NOCOUNT ON,SET XACT_ABORT ON, andSET ANSI_NULLS.
Step 2: Remove Inline SET Statements from the Procedure Body
- Delete or comment out any
SETcommands found directly inside the atomic block body. - Ensure no application-side middleware or ORM (like Entity Framework) injects dynamic
SETcommands into the natively compiled module at runtime.
Step 3: Define Required Options in the ATOMIC Block Header
- Modify the
BEGIN ATOMICclause to include the necessary options as parameters rather than runtime commands. - Use the following syntax structure:
BEGIN ATOMIC WITH (TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english') - Verify that
TRANSACTION ISOLATION LEVELandLANGUAGEare the only two parameters permitted in this clause, as these replace the need for standardSETcommands.
Step 4: Recompile the Module
- Drop the existing procedure using
DROP PROCEDURE [SchemaName].[ProcedureName]; - Re-create the procedure using the corrected script via SSMS or a
sqlcmdcommand line execution:sqlcmd -S localhost -d YourDatabase -i C:\Scripts\FixedProcedure.sql - Check the “Messages” tab in SSMS to confirm the compilation succeeded without throwing Error 10769 again.
Alternative or Verification Steps
- Verification: Execute the procedure manually using
EXEC [SchemaName].[ProcedureName];and confirm that the query returns results without the native compilation error appearing in the SQL Server Error Log located atC:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG. - Alternative Fix: If specific
SETbehavior is strictly required for the business logic, convert the natively compiled procedure back into a standard interpreted T-SQL procedure by removing theNATIVE_COMPILATIONoption from theWITHclause, allowing for full support of session-levelSETcommands.