Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:35:14+00:00 2026-05-23T07:35:14+00:00

Is the Pre-Deployment script (Script.PreDeployment.sql) the best place to put sql commands that create

  • 0

Is the Pre-Deployment script (Script.PreDeployment.sql) the best place to put sql commands that create server level objects (specifically logins in my case)?

I need to create server logins for the database users in the project and this seems the only vaguely logical place to put them as everything else in the project structure (created from reversing our dev db) is database specific. I therefore just wanted to check where others store their server level commands when working with Visual Studio Database Projects.

Many Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:35:14+00:00Added an answer on May 23, 2026 at 7:35 am

    Anything you need prior to deploying your database would be in that script.

    In our case, we add logins in the post deployment script. They are not needed when we deploy the database, and we decided to put all the security related commands in the same place.

    IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = N'$(DefaultLogin)')
    BEGIN
        BEGIN TRY
            CREATE LOGIN [$(DefaultLogin)] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]
        END TRY
        BEGIN CATCH
            -- A try-catch is needed in case a user with a different name is created for the LOGIN specified.
        END CATCH
    END
    GO
    
    IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'$(DefaultLogin)')
    BEGIN
        BEGIN TRY
            CREATE USER [$(DefaultLogin)] FOR LOGIN [$(DefaultLogin)] WITH DEFAULT_SCHEMA=[dbo]
            -- The db_owner role is added to the current database.
            EXEC sp_addrolemember N'db_owner', N'$(DefaultLogin)'
        END TRY
        BEGIN CATCH
            -- A try-catch is needed in case a user with a different name is created for the LOGIN specified.
        END CATCH
    END
    

    Here is the Pre and Post deployment reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my existing (Pre-SVN 1.5) merge strategy, we create a copy of the Trunk
I've found syntax highlighters that highlight pre-existing code, but I'd like to do it
pre tags are super-useful for code blocks in HTML and for debugging output while
I often plug pre-configured lambdas into enumerable methods like 'map', 'select' etc. but the
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
How can I pre pend (insert at beginning of file) a file to all
A UITableViewCell comes pre-built with a UILabel as its one and only subview after
I'm pre-compiling a C program containing Pro*C code with Oracle 10.2 and AIX 5.2
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
Is it currently possible with pre release of ironruby to run rubygems? It seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.