Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I run an Admin site that manages client machines. Each client machine is assigned a specific Sql Server database user. Up to this point I've had to go into Management Studio and create the users. I'd like to do this automatically when I setup a client machine on the Admin site.

Any suggestions on the best way to do this? I'm using ASP.NET MVC 2(old, I know) and Entity Framework 6.

share|improve this question

3 Answers 3

You can set up a feed that automatically imports the credentials to the existing user table in SQL if you have write-back capabilites.

share|improve this answer

create a SQL connection to the server and create the users via TSQL

Web.Config

<connectionStrings>
    <add name="ConnStringDb1" connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

C#

CreateUser()
{
    using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStringDb1"].ConnectionString))
    {
        conn.Open();
        using (SqlCommand cmd = conn.CreateCommand())
        {
            cmd.CommandText = "tsql to create users here";
            cmd.ExecuteNonQuery();
        }
    }

}
share|improve this answer

You could do this via SQL directly when the client machine is set up by using the CREATE USER / CREATE LOGIN statement (and assigning its privileges accordingly). You can get the SQL to guide you in doing so if you start adding the user in management studio then hit the script button at the top left of the dialog it will show you the SQL script to dynamically create the user account. Create User SQL Docs Create Login SQL Docs

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.