We have a SQL Server database project (.sqlproj) in Visual Studio 2012, which we use as a source for our database schema. One of the great things he does is create SQL to update the schema when you release the code.
We have 3 profiles - dev, test, live - everything works fine.
We recently changed our live database from “simple” recovery to “full” recovery. Everything was great until we tried to launch our next deployment for dev and test. We do not want to change the recovery mode from Simple to Full to dev and test - we do not need to change it. However, when we publish the database project, he now wants to install it.
I want to install a recovery model, based on which I use the publication configuration. I tried to create a variable and assign it in xml projects:
<Recovery>$(RecoveryModel)</Recovery>
but he is still trying to set it to “Full” in the deployment script:
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\" :setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL11.SQL2012\MSSQL\DATA\" :setvar RecoveryModel "Simple" GO :on error exit GO :setvar __IsSqlCmdEnabled "True" GO IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True' BEGIN PRINT N'SQLCMD mode must be enabled to successfully execute this script.'; SET NOEXEC ON; END GO IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)') BEGIN ALTER DATABASE [$(DatabaseName)] SET RECOVERY FULL WITH ROLLBACK IMMEDIATE; END
My current job is to create a script in the folder after deployment to determine which server I'm on, and then install the recovery model again if it is dev or test. This does not seem to be the best solution.
Is there a way to set database properties using SQLCMD variables?
source share