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 6722603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:28:00+00:00 2026-05-26T09:28:00+00:00

I want to create an Sql Server Authentication Account, not a user in the

  • 0

I want to create an Sql Server Authentication Account, not a user in the database or in the account.

What i mean is that i want to create an account so i can login from it when i start the sql server, using SQL Transaction or using C#.

  • 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-26T09:28:01+00:00Added an answer on May 26, 2026 at 9:28 am

    There are only two modes that I know you can use: Windows or SQL Server Authentication. This means you are limited to only two choices: You either use a Windows account, or you create an SQL Server login that you can use to authenticate.

    EDIT:

    To programmatically create an sql server login, you could use Sql Server Management objects. I notice you didn’t say whether you want to do this from a Windows (desktop) or Web application. To use Sql Server Management to create a login (or do any sort of “management”), the code would need to run with higher privileges – say local or domain account with sufficient privileges to administer the SQL server instance.

    You will need to add references to (you could use version 9.0 of the assemblies):

    Microsoft.SqlServer.ConnectionInfo
    Microsoft.SqlServer.Smo
    Microsoft.SqlServer.SqlEnum
    

    With that, the following code is enough to create an SQL login and also add the user to your target database

            var serverName = "."; // Your SQL Server Instance name
            var databaseName = "Test"; // Your database name
            var loginName = "testuserY"; // Your login name (should not exist - or you should add code to check if the login exists)
    
    
            Server svr = new Server(serverName);
            var db = svr.Databases[databaseName];
            if (db != null)
            {
                // You probably want to create a login and add as a user to your database
                Login login = new Login(svr, loginName);
                login.DefaultDatabase = "master"; // Logins typically have master as default database
                login.LoginType = LoginType.SqlLogin;
                login.Create("foobar", LoginCreateOptions.None); // Enter a suitable password
                login.Enable();
    
                User user = new User(db, loginName);
                user.UserType = UserType.SqlLogin;
                user.Login = login.Name;
                user.Create();
                // add a role
                user.AddToRole("db_owner");
            }
    

    You will need to add:

    using Microsoft.SqlServer.Management.Smo;
    

    You can add try{} catch{} blocks and plumbing code to make it more robust you would recover gracefully in case of failure

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

Sidebar

Related Questions

I can connect to remote SQL Server database and I want to create a
I want to create a global connection class from Sql server database to vb.net
I want to create a user on a SQL Server 2005 database using the
I want to create a program, that will use SQL Server 2008 database. During
I want to create a SQL Server Express database on my local machine and
I want to create a list of columns in SQL Server 2005 that have
I want to create a stored procedure (on SQL Server 2005) that fetches a
I need to create an entirely new Sql Server 2008 database and want to
I want to create an SQL script that creates a database. Right now, I
I want to create ASP.NET 4.0 dynamic pages loaded from my MS SQL server.

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.