2017-03-17 72 views
2

我deployng DACPAC與以下部署後SCRIPT1:T-SQL部署後腳本如何引用變量

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

然而,當我嘗試引用此部署後SCRIPT2,部署失敗:

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."' 
+0

你有多個標記爲「Post-Deploy」的文件嗎?您應該只有一個後期部署文件,並使用:r標籤包含要在該後期部署腳本中運行的其他文件。 –

+0

我只有1個部署後腳本 – WinBoss

回答

3

動態SQL是最後的避難所歹徒:

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

爲我工作,雖然在本地部署,而不是通過Azure D SC。

這是一種通用技術,用於執行通常不支持TSQL變量替換的「DBA類型」活動。


請注意未來的讀者:這個招數顯然有效,也就是說OP已經標記爲答案。但是,由於工作站和構建服務器之間的DacFX版本不同,因此只需要,這可能是,請參閱another SO post relating to the same error message