CREATE DATABASE statement not allowed within multi-statement transaction

后端 未结 5 1550
不知归路
不知归路 2021-02-13 22:40

I\'m trying to build a quick test that deletes and recreates a database every time it runs. I have the following:

[TestClass]
public class PocoTest
{
    privat         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-13 23:03

    For your information, this error occurs by design and it happens whenever non-transactionable commands are issued to Microsoft SQL Server within an active transaction.

    The solution is, therefore, granting that Database.CreateIfNotExists() hits the database out of any transaction scope. Remember, SQL Profiler is your friend.

    You can get a roughly updated list of commands that are not allowed to run whithin transactions.

    Note: In case one wonders why am I providing a list based on a Sybase's product, bear in mind that Microsoft SQL Server shares most of its basic genetic with Sybase' engine. For further reading, refer to https://en.wikipedia.org/wiki/Microsoft_SQL_Server

提交回复
热议问题