Question

We have a solution with three database projects. All three produced dacpacs are deployed sequentially but for some reason, one of these dacpacs does not run the post-deployment script.

We're using sqlpackage to create a diffscript, and the diffscript does correctly include the post-deployment statements.. here's a snippet

IF EXISTS (SELECT * FROM #tmpErrors) ROLLBACK TRANSACTION
GO
IF @@TRANCOUNT>0 BEGIN
PRINT N'The transacted portion of the database update succeeded.'
COMMIT TRANSACTION
END
ELSE PRINT N'The transacted portion of the database update failed.'
GO
DROP TABLE #tmpErrors
GO
/*
Post-Deployment Script Template                         
--------------------------------------------------------------------------------------
 This file contains SQL statements that will be appended to the build script.       
 Use SQLCMD syntax to include a file in the post-deployment script.         
 Example:      :r .\myfile.sql                              
 Use SQLCMD syntax to reference a variable in the post-deployment script.       
 --------------------------------------------------------------------------------------
*/
print 'SCRIPT: dbo.MEMTYPES.data.sql'

Where: a) The Comment is in the Header postdeployment.sql script, which calls other scripts using the standard syntax : :r .\dbo.MEMTYPES.data.sql , and b) The line " print 'SCRIPT: dbo.MEMTYPES.data.sql'" is the first line of the first child script defined in the postdeployment script.

However, when run, the log of the deployment ends with the line:

The transacted portion of the database update succeeded.

Which means the dacpac schema changes were applied (and they were) but presumably no attempt was made to continue in the script to run the post deployment tasks.

Any ideas?

Was it helpful?

Solution

As it's a couple of months after I posted the question, and https://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ I guess I should state what the outcome was...

I couldn't find rhyme or reason for the issue other than removing the comments resolved the issue. Now that this has in effect been included in our rules to follow, we haven't come across this issue since.

OTHER TIPS

As user3683706 mentioned above, the Build Action of your post deployment script has to be PostDeploy (as shown in the selected file below). And there can only be one post-deployment script.

What if you want multiple script? You can reference them in one script like this

:r .\Post-Deployment_Scripts\Events.sql

enter image description here

Let me know if any questions! Upvotes are greatly appreciated!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top