Showing posts with label database project. Show all posts
Showing posts with label database project. Show all posts

Thursday, August 23, 2012

SQL Server Database Project - Warning is shown as Error

While trying to build a database project, I was getting an error:
Error:  SQL01945: Warning! The maximum key length is 900 bytes. The index 'xxx' has maximum length of 1024 bytes. For some combination of large values, the insert/update operation will fail.

Although this was a warning, the project was failing to build and it was shown as a error.

The fix was to edit the project file in xml and set TreatTSqlWarningsAsErrors to False

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <OutputPath>.\sql\debug\</OutputPath>
    <BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
    <TargetDatabase>xxx</TargetDatabase>
    <TreatTSqlWarningsAsErrors>False</TreatTSqlWarningsAsErrors>
    <SuppressTSqlWarnings />
    <NoWarn>
    </NoWarn>
  </PropertyGroup>

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.