Showing posts with label sqlcmd. Show all posts
Showing posts with label sqlcmd. Show all posts

Wednesday, November 23, 2011

Running SQLCMD Database Deployment scripts from SQL Management Studio

This is a very common scenario for database projects created in Visual Studio:
  • Create a database project
  • Right click the project and select Properties
  • Set "Deploy action" to "Create a deployment script (.sql)
  • Right click the project and select Deploy
This will generate the .sql file which can be used for deploying the database separately.

However, if you try to run this file from SQL Management Studio, it will result in errors.

This is because the script contains some sqlcmdvars (:setvar) which are specific to SQLCMD. If you run the same script using sqlcmd.exe, it would work fine.
If you want to run it from SQL Management Studio, click Query->SQLCMD Mode and then execute the query.

Wednesday, October 12, 2011

SQLCMD - QUOTED_IDENTIFIER is OFF

If you want to deploy the Differential script on a Database in an automated way, the most common way is to use SQLCMD. For example:

sqlcmd -S Server-d Database1 -U UserName -P Password -i DatabaseBuild-ProdDiff.sql

However, when you run this script, QUOTED_IDENTIFIER is set to OFF

When running the stored procedures, you might see errors like:
Message: UPDATE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'.

The reason for this is that QUOTED_IDENTIFIER is not set to ON
To set it to ON, you should pass the -I argument, For example:
sqlcmd -I -S Server-d Database1 -U UserName -P Password -i DatabaseBuild-ProdDiff.sql