CREATE DATABASE statement not allowed within multi-statement transaction

后端 未结 5 730
广开言路
广开言路 2021-02-13 22:50

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:22

    Try this code

    using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress))

    {
    var sqlCommand = String.Format("Create DATABASE [{0}]", "TempBackupDB"); _context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, sqlCommand);

    ts.Complete();

    }

提交回复
热议问题