Sql Server 2012. How to solve the problem of lack of access rights?



  • SQL Server 2012. A user has been established in the database in such a way as:

    CREATE LOGIN MyUser1
        WITH PASSWORD = '123';
    USE Банк;
    GO
    CREATE USER MyUser1 FOR LOGIN MyUser1;
    GO 
    

    I'm connected to the database from the C# application with SqlConnection, clearly indicating password and login in the connection line. In the annex, I tried to realize the possibility of creating a new user in such a way as:

    private void CommandExecute(String command) 
    {
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = Connection;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = command;
    cmd.ExecuteNonQuery();    
    }
    

    CommandExecute("CREATE LOGIN " + Login + " WITH PASSWORD = '" + Password + "';");
    CommandExecute(" CREATE USER " + Login + " FOR LOGIN " + Login + ";");
    CommandExecute("INSERT INTO Client(Client.FullName,Client.PhoneNumber,Client.Address,Client.Login)VALUES('" + FullName + "','" + Phone + "','" + Address + "','" + Login + "')");

    The whole point of this code is simply fulfilling the first request on the client's side. At the time of implementation of this code, there is an error of implementation, stating that the user(s) has no authorization to perform the operation. I understand that the problem is solved by building on the side of the server, I tried to solve it, but it didn't work. Enlighten me how to do it. Thank you.



  • Once the user has been registered, he must be given permission.
    T-SQL by https://msdn.microsoft.com/ru-ru/library/ms178569(v=sql.120).aspx ♪

    For CREATE USER Request permission ALTER ANY USER




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2