1

I'm deployng DACPAC with with the following post-deployment script1:

ALTER DATABASE [$(DatabaseName)] 
MODIFY FILE (NAME = [$(DatabaseName)], 
             SIZE = 100MB, MAXSIZE = UNLIMITED, FILEGROWTH = 20%)

However, when I try to reference this post-deployment script2, deployment fails:

ALTER DATABASE [$(DatabaseName)] 
MODIFY FILE (NAME = [$(DatabaseName)], 
             SIZE = $(size), MAXSIZE = UNLIMITED, FILEGROWTH = 20%)

So, my question is what is the correct syntax to pass as size?

I use this command to initiate the script (first script1 works, script2 doesn't)

$resourceGroup = "SQL1"
$vmName = "SQL1"
$storageName = "sql1artifactsstorage111"
$ConfigurationPath = "C:\DSC\Ext\deployDB.ps1"
$ConfigurationName = "deployDB"
$configurationArchive = "deployDB.ps1.zip"
#Publish the configuration script into user storage
Publish-AzureRmVMDscConfiguration -ConfigurationPath $ConfigurationPath -ResourceGroupName $resourceGroup -StorageAccountName $storageName -force
#Set the VM to run the DSC configuration
$configurationArguments = 
@{
    Credential = Get-Credential;
    DatabaseName = 'Database1' 
    size = '100MB'
}
Set-AzureRmVmDscExtension -Version 2.22 -Name dscExtension -ResourceGroupName $resourceGroup -VMName $vmName -ArchiveStorageAccountName $storageName -ArchiveBlobName $configurationArchive -AutoUpdate:$true -ConfigurationName $ConfigurationName -ConfigurationArgument $configurationArguments

This is the error DSC shows:

Dac Deploy Failed: 'Exception calling "Deploy" 
with "3" argument(s): "An error occurred during deployment plan generation. 
Deployment cannot continue."'
2
  • Do you have multiple files tagged as "Post-Deploy"? You should only have one post-deploy file and use a :r tag to include other files to run in that post-deploy script. Commented Mar 17, 2017 at 17:16
  • I have only 1 post-deployment script Commented Mar 17, 2017 at 17:44

1 Answer 1

3

Dynamic SQL is the last refuge of the scoundrel:

EXEC ('ALTER DATABASE [$(DatabaseName)] MODIFY FILE (NAME = [$(DatabaseName)],SIZE = $(size), MAXSIZE = UNLIMITED, FILEGROWTH = 20%)');
GO

worked for me, albeit in a local deployment rather than through Azure DSC.

This is a general purpose technique for doing these "DBA-esque" activities that often don't support TSQL variable substitution.


Note to future readers: this trick apparently worked, which is to say the OP has marked it as the answer. However, it was probably only necessary due to differing versions of DacFX between the workstation and the build server, see for example another SO post relating to the same error message.

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.