0

I want to enable broker for my database in an Entity Framework migration. I add a migration to my project and write this code in the Up method :

Sql("ALTER DATABASE current SET ENABLE_BROKER", true);

This code runs correctly for SQL Server 2014, but when I change my target database to SQL Server 2008 R2 Express, I get this error:

Incorrect syntax near the keyword 'current'

How do I change the code to run properly for all type of SQL Server instances?

1 Answer 1

1

Before SQL 2012 you have to use the database name. Something like this batch:

declare @sql nvarchar(max) = N'ALTER DATABASE ['+db_name()+N'] SET ENABLE_BROKER;'
exec( @sql );

should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.