SQL SERVER – Memory Optimized Tables, Transactions, Isolation Level and Error

Today we will see an interesting story about Memory Optimized Tables, Transactions, Isolation Level and Error. While I was working with my customer with Comprehensive Database Performance Health Check, we came across a very interesting situation.

SQL SERVER - Memory Optimized Tables, Transactions, Isolation Level and Error isolationlevel1-800x205

My customer was a financial institute and they had very high transactions every single second. We had successfully implemented In-Memory OLTP technology for them. There were situations where we have to use the Memory-Optimized tables and disk-based regular tables in the single transactions.

Every time whenever we ran query which was accessing memory-optimized table and disk-based table, we were getting an error and my client did not want any error.

Here is the script when I ran it gave us an error:

FROM [dbo].[MemoryOptimizedTable] mt
INNER JOIN [dbo].[DiskBasedTable] dt ON mt.ID = dt.ID

Please note in the above script one table is memory optimized and another one is disk based table. Whenever I ran the script it gave me following error.

Msg 41368, Level 16, State 0, Line 3
Accessing memory optimized tables using the READ COMMITTED isolation level is supported only for autocommit transactions. It is not supported for explicit or implicit transactions. Provide a supported isolation level for the memory optimized table using a table hint, such as WITH (SNAPSHOT).
Msg 3902, Level 16, State 1, Line 8
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

The reason for the error is that in SQL Server In-Memory OLTP whenever you try to access any disk-based and memory optimized table in the single transactions, it will give you an error as that is not directly supported unless you change the isolation of the query or database.

WORKAROUND/SOLUTION for Memory Optimized Tables

Here is the simple solution of the above error.

When you change the isolation level for the database to MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT the error will go away and your SQL Server will support implicit or explicit transactions cross-container (across disk and memory)

-- for Cross Container Transactions

Well, that’s it!

Reference: Pinal Dave (https://blog.SQLAuthority.com)

In-Memory OLTP, SQL Error Messages, SQL Memory, SQL Scripts, SQL Server, SQL Transactions, Transaction Isolation
Previous Post
SQL SERVER – Script: Find Last System / Operating System Reboot or Restart Time
Next Post
Database Diagram – Available Again in SQL Server Management Studio 18.1 Onwards

Related Posts

1 Comment. Leave new

  • Paresh Motiwala
    May 14, 2021 6:50 pm

    Hi Pinal, thanks as always for making crazy problems so simple to overcome. Would this change affect other tables or objects? I think not….but just need your thoughts.


Leave a Reply