I am trying to do a deploy using DacFx, and need to place the database in single user mode so that nobody (but the dac update context) can update the database.
_deployOptions = new DacDeployOptions
{
BlockOnPossibleDataLoss = false,
IncludeCompositeObjects = true,
IncludeTransactionalScripts = true,
DropConstraintsNotInSource = deployConfig.DropConstraintsNotInSource,
DropIndexesNotInSource = deployConfig.DropIndexesNotInSource,
DropDmlTriggersNotInSource = false,
DeployDatabaseInSingleUserMode = true
};
DacServices.Deploy(dacpac, _dbName, true, _deployOptions);
The deploy process (I have confirmed) does NOT place the database into single user mode; however, if I use
var script = DacServices.GenerateDeployScript(dacpac, _dbName, _deployOptions);
The resulting script does have the single user set at beginning, and multi user set at the end. Is there any reason why executing a Deploy doesn't correctly use the DeployDatabaseInSingleUserMode setting as one would expect? At the end of the day I just need to make sure no database updates can occur during this update - if there is another way (besides single-user) then I am open to suggestions.
I have also tried generating\executing the script, but I am fearful that the script may become too large (plus there are issues with $(DatabaseName) being used in the script which means I'll have to massage it before actually executing it).
Relation Question: Publish dacpac in single user mode using Microsoft.SqlServer.Dac.DacServices
Thanks very much.
This was an easy one - my SSDT (SQL server data tools) needed an update. After updating to the latest version (11.1.50717.0) the setting started working.