0

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.

3 Answers 3

0

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

0

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();
        }
    }

}
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.