deploying a supplied package to a database时:
DacServices service = new DacServices(connectionString);
DacPackage dacpac = DacPackage.Load(dacpacPath);
DacDeployOptions ddo = new DacDeployOptions();
ddo.BlockOnPossibleDataLoss = false;
service.Deploy(dacpac, dbName, true, ddo);
如何通过取消令牌取消它,这会回滚整个部署操作吗?
因此,我可以创建一个取消令牌并将其传递给Deploy方法,但之后如何取消它?但是,它会回滚整个操作吗?
CancellationToken token = new CancellationToken();
service.Deploy(dacpac, dbName, true, ddo, token);
答案 0 :(得分:2)
将DacDeployOptions.IncludeTransactionalScripts标志设置为" true"将在事务中包装模型部署步骤。如果部署失败或被取消,引擎将尝试回滚这些步骤。请注意,部署前/后脚本步骤不会放在事务中,因此如果您使用这些步骤,则需要自己进行事务处理。这是因为a)引擎没有解析它们或试图理解它们的内容,b)它们可能包含与事务不兼容的代码,因此引擎不会尝试强制执行事务性。 / p>
要实际呼叫取消,您可以使用CancellationTokenSource。我认为代码看起来像:
DacServices service = new DacServices(connectionString);
DacPackage dacpac = DacPackage.Load(dacpacPath);
DacDeployOptions ddo = new DacDeployOptions();
ddo.BlockOnPossibleDataLoss = false;
ddo.IncludeTransactionalScripts = true;
CancellationTokenSource tokenSource = new CancellationTokenSource();
service.Deploy(dacpac, dbName, true, ddo, tokenSource.Token);
tokenSource.Cancel();