How to Fix SQL Server Error 41368 (Msg 41368)
You get sql server error 41368 when an explicit transaction reads a memory optimized table with read committed isolation. To fix it, use autocommit mode or switch the table query to a higher isolation level. This failure returns severity 16 from the database engine. It stops your query right away to prevent bad transaction state. Teams see this error during app updates or manual data checks. What causes sql server error 41368 in the database engine The official message for sql server error 4
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You get sql server error 41368 when an explicit transaction reads a memory optimized table with read committed isolation. To fix it, use autocommit mode or switch the table query to a higher isolation level.
This failure returns severity 16 from the database engine. It stops your query right away to prevent bad transaction state. Teams see this error during app updates or manual data checks.
What causes sql server error 41368 in the database engine
The official message for sql server error 41368 states the exact rule. Accessing memory optimized tables using the read committed isolation level works only for autocommit transactions. Explicit or implicit transactions break this rule when they use read committed mode.
Standard disk tables and memory optimized tables handle locks and versions in different ways. Disk tables often use read committed isolation by default for multi-statement work. Memory optimized tables require snapshot, repeatable read, or serializable isolation inside open transactions.
When a client starts a transaction and touches a memory optimized table, the engine checks the isolation rule. If the session still uses read committed mode, the engine raises code 41368. Even a simple read query inside an open transaction block will fail.
Many database tools and app drivers wrap queries in explicit transactions behind the scenes. An engineer might run a quick read query in a client tool with implicit transactions turned on. That hidden transaction triggers the error on any memory optimized table.
How to diagnose and fix the failure in production
First, find which query and session hit the severity 16 error in your logs. Check whether the session runs an explicit transaction or uses implicit transaction mode. Look at the tables in the query to spot which ones live in memory.
You have three safe ways to fix this error without granting extra rights. First, you can run single statements in autocommit mode when read committed is enough. Second, you can add a table level isolation hint like snapshot for the memory optimized table.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Third, you can enable memory optimized elevation to snapshot at the database level. This database setting upgrades the isolation level for memory optimized tables by default. It lets existing app queries run without code changes on every single statement.
Keeping access safe while fixing transaction errors
Engineers often ask for broad admin rights to change database settings during an outage. The fixed role for database owners can perform all maintenance tasks and even drop the database. You should not grant that role just to debug a query failure.
A database user is the identity of a login when it connects to a database. For people who need access to many databases on an instance, a login in master is common. For access to one or a few databases, a contained database user with a password is an option.
Keep fixing sessions on least privilege roles while you test isolation hints. Members of the fixed data reader role can read all data from all user tables and views. The permissions assigned to fixed database roles cannot be changed.
If an engineer needs to test write transactions, use the fixed data writer role on a test database. Members of that role can add, delete, or change data in all user tables. You should also apply data masking so results rewrite emails, phone numbers, and card numbers.
Add runtime guardrails beside SQL Server
Role grants and network rules are needed setup for SQL Server. Still, an allowed user or agent tool can send a bad delete or read raw customer fields over a valid session. In practice, hoop.dev sits inline in the TDS protocol beside the database as a sidecar for your SQL Server. For every query an agent or human runs in production, hoop.dev decides whether to pass, mask, block, or escalate it for review.
With hoop.dev SQL Server controls, rules refuse banned statements before they run, hold risky queries for human review, and mask matched sensitive values in supported result columns in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for HIPAA, PCI DSS, SOX, and GDPR audits. See the source on GitHub.
Frequently asked questions
Why does sql server error 41368 happen on a simple select query?
Your SQL client or app driver likely started an explicit or implicit transaction before the select statement. Memory optimized tables reject read committed queries unless they run as single autocommit statements.
Can I fix error 41368 without rewriting all my app queries?
Yes, a database admin can turn on the database setting that elevates memory optimized tables to snapshot isolation. Once enabled, the engine upgrades read committed transactions on those tables to snapshot mode by default.
Do engineers need owner permissions to test query fixes for Msg 41368?
No, engineers only need standard read or write roles to test transaction hints and autocommit behavior. Only a database level setting change requires higher admin rights through an approved change process.
Related guides
In this post