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

浪子不回头ぞ 提交于 2020-01-03 13:39:10

问题


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:


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();


来源:https://stackoverflow.com/questions/31041788/publish-dacpac-in-single-user-mode-using-microsoft-sqlserver-dac-dacservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!