2

我正在使用以下部署后脚本 1 部署 DACPAC:

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

但是,当我尝试引用此部署后脚本 2 时,部署失败:

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

所以,我的问题是传递大小的正确语法是什么?

我使用此命令启动脚本(第一个 script1 有效,script2 无效)

$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

这是 DSC 显示的错误:

Dac Deploy Failed: 'Exception calling "Deploy" 
with "3" argument(s): "An error occurred during deployment plan generation. 
Deployment cannot continue."'
4

1 回答 1

3

动态 SQL 是流氓的最后避难所:

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

为我工作,尽管是在本地部署中而不是通过 Azure DSC。

这是执行这些“DBA 式”活动的通用技术,这些活动通常不支持 TSQL 变量替换。


未来读者请注意:这个技巧显然有效,也就是说 OP 已将其标记为答案。但是,由于工作站和构建服务器之间的 DacFX 版本不同,这可能只是必要的,例如,请参阅与相同错误消息相关的另一篇 SO 帖子

于 2017-03-17T17:05:42.067 回答