Share via

How to deploy dacpac excluding user logins into other environments

Subhomoy Chakraborty 106 Reputation points
2023-04-11T14:26:07.0033333+00:00

Hi Team, I have created one dacpac file in dev environment having several user logins and roles. But I am not able to exclude the logins and roles while trying to deploy the DACPAC into other environments. I tried from visual studio --debug -- properties and exclude the user logins and built the solution again. But still the users are appearing post deployment. My requirement is only deploying the db objects and nothing else while creating and deploying the DACPAC. Please suggest.

SQL Server | Other

4 answers

Sort by: Most helpful
  1. Guoxiong 8,221 Reputation points
    2023-04-12T13:25:07.37+00:00

    Hi Subhomoy, You can create a script (Not in build) for all of the user logins or one script for one user login if you want to control each of them for the deployment. And then you can create a SQLCDM variable, i.e., $(DeployUserLogin) with default value 0. In the user login script, you can add the IF statement:

    IF $(DeployUserLogin) = 1 
    BEGIN 
    	-- User login script is here
    END
    

    This way you can control the post deployment scripts for the user logins. If you do not want to deploy them, you can set the variable to 0, otherwise 1.

    1 person found this answer helpful.
    0 comments No comments

  2. Chad B 5 Reputation points
    2023-04-11T16:49:18.1733333+00:00

    You'll have to use SqlPackage to deploy the dacpac, see this doc:

    https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-publish?source=recommendations&view=sql-server-ver16#properties-specific-to-the-publish-action

    Hoping someday Azure Data Studio gets more options around dacpac deployment.

    1 person found this answer helpful.

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Seeya Xi-MSFT 16,676 Reputation points
    2023-04-12T02:43:13.8233333+00:00

    Hi @Subhomoy Chakraborty,

    Another approach is to use a pre-deployment script to drop the user logins and roles before deploying the DACPAC, and then create them again after the deployment is complete. You can create a SQL script to drop the logins and roles, and then include it in the "Pre-Deployment Script" section of the DACPAC project properties.

    Please refer to this document: https://learn.microsoft.com/en-us/sql/ssdt/how-to-specify-predeployment-or-postdeployment-scripts?view=sql-server-ver16

    Best regards,

    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.