RenegadeAndy
RenegadeAndy

Reputation: 5690

C# Microsoft SQL Server 2012 GRANT syntax

I have a question about the grant syntax for me specific scenario.

I have created a database whose instance name is : MYINSTANCE My DB is called: MyDB

I have run an SQL command which makes a new table, and now I want to grant Select and Update privileges to my user.

I am using a connection string as follows with Integrated Security turned on :

Data Source=.\\MYINSTANCE;Initial Catalog=MyDB;Integrated Security=true

The Grant syntax I am trying alter is:

sqlCommand = new SqlCommand(
    @"GRANT SELECT, UPDATE ON tblUnits TO [INET_ACCOUNT]", sqlConnection);
                    sqlCommand.ExecuteNonQuery();   

Now my database owner is : Andy-PC\Andy I am wondering what to replace the TO [INET_ACCOUNT] for with my current setup?

Upvotes: 0

Views: 315

Answers (2)

RenegadeAndy
RenegadeAndy

Reputation: 5690

The answer was yes TO[Andy-PC\Andy] fixed the problem!

Upvotes: 0

thinkster
thinkster

Reputation: 624

As you may know its [INET_ACCOUNT] refers to the principal to which the permission is being granted. So you would be updating that with the user requiring the Select access for that table. Following is the syntax for GRANT from MSDN:

GRANT <permission> [ ,...n ] ON [ OBJECT :: ][ schema_name ]. object_name [ ( column [ ,...n ] ) ] TO <database_principal> [ ,...n ] [ WITH GRANT OPTION ] [ AS <database_principal> ] <permission> ::= ALL [ PRIVILEGES ] | permission [ ( column [ ,...n ] ) ] <database_principal> ::= Database_user | Database_role | Application_role | Database_user_mapped_to_Windows_User | Database_user_mapped_to_Windows_Group | Database_user_mapped_to_certificate | Database_user_mapped_to_asymmetric_key | Database_user_with_no_login .

Upvotes: 1

Related Questions