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

  • Home
  • SEARCH
  • 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 6744557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:05:53+00:00 2026-05-26T12:05:53+00:00

For security purposes i am droping all the server roles from each login in

  • 0

For security purposes i am droping all the server roles from each login in the database and leaving only the “sa”:

        //Get all server info for this instance
        Server oServer = new Server(@"YAHYA-PC\SQLEXPRESS");

        //Get all logins
        var users = oServer.Logins;
        //Get all server roles in the current instance
        ServerRoleCollection oServerCollection = oServer.Roles;
        //foreach login name drop all roles 
        foreach (Login oLogin in users)
        {
            if (oLogin.Name != "sa")
            {
                foreach (ServerRole oRole in oServerCollection)
                {
                    if (oRole.Name != "public")
                    {
                        oRole.DropMember(oLogin.Name);
                    }
                }
            }
        }

It was a success at first, but after running the code for the second time it turns out that the Server object connects via Sql Windows Authentication so it keeps giving me an exception since i omitted all the server roles from the Sql Windows Account. is there any possible way to make the Server object connects via Sql Server Account Login ?

Edit with the answer:

ServerConnection oConnection = new ServerConnection(@”ServerInstance”,”UserName”,”Password”);
Server oServer = new Server(oConnection);

  • 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-26T12:05:54+00:00Added an answer on May 26, 2026 at 12:05 pm

    Try changing the connection string to: Provider=SQLNCLI10;Server=myServerAddress;Uid=myUsername;Pwd=myPassword

    Update: While this may have given you the answer you were originally seeking, I agree with everything in Dave Markle’s post and should have mentioned that earlier.

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

Sidebar

Related Questions

For security purposes, all system, images documents are located outside my website root directory.
This question is mainly for security purposes. I need to know if it is
We need to protect a class from having static methods for security purposes. We
For security purposes, is the primary identifier of an Active Directory user the 'logonname'
We need to move off traditional FTP for security purposes (it transmits it's passwords
I have a page (index.php) that takes a GET variable from the URL and
I have a page that takes a GET variable, q from the URL using
I'm using VS2010,C#,SQL Server to develop my ASP.NET web app, although this is not
Hey all, I would like some advice from the programming community. I am building
I'm wondering whether for security purposes it would be worth using the session_name() function

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.