Visual Studio for Database Professionals can not use variables in build

I was happy to find that Visual Studio for DB Professionals (SP1) allowed you to add variables for your database scripts on a configuration level.

Great! I thought I could generate SQL scripts for my entire database depending on it being a production or test target. How useful!

Well.. not really…

As try as I might, I could not get those variables to appear in my SQL script.

I got an answer from the forums to say that basically this can ONLY be done when ‘deploying’ a database.. building one is apparently not reason enough for DB Pro to replace variables.

They said that the SQLCMD command might want to override variables, which is why they don’t replace them during build.

I admit.. the ‘deploy’ functionality of DB Pro is great.. it is smooth and simple.

BUT I can not (nor would I ever) use it to deploy to a production database. For this task, I would generate a SQL script (via build) and give it to the production support team. I would never come close to touching that database.

So… basically this great feature is rendered useless…

I had to instruct my SQL script to examine the database name for environment variables

IF DB_NAME() == ‘MyProductionDatabase’


UPDATE: I was helpfully given this link which clarifies the use of the SQLCMD to handle this

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s