SSDT事务发布? [英] SSDT transactional publish?

查看:81
本文介绍了SSDT事务发布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将msbuild与SSDT结合使用,我尝试了IncludeTransactionalScripts,但它似乎只将每个语句放在一个单独的事务中. 是否可以将多个数据库项目作为事务发布? 如果没有,我至少可以确保每个项目都在事务中发布吗?

Using msbuild with SSDT, I have tried IncludeTransactionalScripts, but it seems to only put each statement in an individual transaction. Is it possible to publish multiple database projects as a transaction? If not, can I at least make sure that each Project is published within a transaction?

推荐答案

对于发现此问题但不知道在哪里寻找的其他人:

For anybody else who found this question, but didn't know where to look:

有一个发布设置包括事务脚本",该设置在发布脚本的开始处开始一个事务.然后,它将每个模式更改包装在脚本中以进行错误检查.在出现错误时,将回滚事务,并增加错误日志,但随后从头开始事务.如果没有错误,则事务将继续未提交

There is a publish setting, "Include transactional scripts", that begins a transaction at the start of the publish script. It then wraps each schema change in the script in an error check. On errors, the transaction is rolled back and an error log is incremented, but then the transaction is started from scratch. If there is no error, the transaction continues uncommitted

BEGIN TRANSACTION

...alter object here

IF @@ERROR <> 0  @@TRANCOUNT > 0
BEGIN
    ROLLBACK;
END

IF @@TRANCOUNT = 0
BEGIN
    INSERT  INTO #tmpErrors (Error)
    VALUES                 (1);
    BEGIN TRANSACTION;
END

最后,如果注册了错误,则会回滚整个事务:

At the end, if errors have been registered, the whole transaction is rolled back:

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


请注意(如上面的评论所述),它不包含您的部署前/部署后脚本,因此您应谨慎包装这些脚本


Note (as in the comments above) that this doesn't include your pre-/post-deployment scripts, so you should be careful to wrap these separately

下面的链接指向Peter Schott的博客-我认为是同一个人在上面发表评论-谢谢:)

The link below is to Peter Schott's blog - it's same guy who commented above I think - thanks :)

http://schottsql.blogspot.co. uk/2012/11/ssdt-publishing-your-project.html

他很好地解释了使用SSMS时如何配置这些设置

He explains nicely how to configure these settings when using SSMS

使用Visual Studio 2015,我发现默认情况下未设置包括事务脚本"设置.在[高级...]选项卡下定义发布设置([内部版本] >> [发布{项目名称} ...])时,必须选择以下选项:

Using Visual Studio 2015, I found that the "Include transactional scripts" setting was not set by default. You have to select this when defining the Publish settings ([Build]>>[Publish {project name} ...]) under the [Advanced...] tab:

这篇关于SSDT事务发布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆