As part of my Entity Framework deployment I'm trying to deploy some scripts onto a newly created database, however I got the following error;
ALTER DATABASE statement not allowed within multi-statement transaction.
My Code;
internal sealed class Configuration : DbMigrationsConfiguration<DBContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(DBContext context)
{
context.Database.ExecuteSqlCommand(
@"ALTER DATABASE MyDB SET ENABLE_BROKER
CREATE QUEUE NewCarShareQueue;
CREATE SERVICE NewCarShareService ON QUEUE NewNewCarShareQueue
([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]);");
}
}
I've tried the following as well, making sure only one transaction is going through at once, and not shown here but disposing the current context and recreating it;
internal sealed class Configuration : DbMigrationsConfiguration<DBContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(DBContext context)
{
context.SaveChanges();
context.Database.ExecuteSqlCommand(
@"ALTER DATABASE MyDB SET ENABLE_BROKER");
}
}