Publish dacpac in single user mode using Microsoft.SqlServer.Dac.DacServices

1.1k views Asked by At

I want to publish dac pac in single user mode to prevent unnecessary db changes while database is upgrading. For that I have used Deploy function in Microsoft.SqlServer.Dac.DacServices.

That function there is a argument DacDeployOptions options. I have set DeployDatabaseInSingleUserMode = true in that options. Even though it is set to true I am able to do db operation while dacpac is deploying.

Is there anything I am missing? or Is there any other way to achieve this.

Help will be Appreciated!

1

There are 1 answers

0
BeardOfTriumph On

Which version of DacFX are you using? If it's not the latest, best get the latest, because a lot of the older ones are not very good at recognizing the options you specify.

Alternatively, you could do this(It's what i've done, instead of trying to get DacFX to work properly.

            ServerConnection connection = new ServerConnection(ServerName);
            Server sqlServer = new Server(connection);
            Database QADatabase = sqlServer.Databases[DatabaseName];
            QADatabase.DatabaseOptions.UserAccess = DatabaseUserAccess.Single;
            QADatabase.Alter(TerminationClause.RollbackTransactionsImmediately);
            QADatabase.Refresh();

//DACPAC logic goes here

            QADatabase.DatabaseOptions.UserAccess = DatabaseUserAccess.Multiple;
            QADatabase.Alter(TerminationClause.RollbackTransactionsImmediately);
            QADatabase.Refresh();