Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GRANT query

Author  Topic 

hemaljoes
Starting Member

7 Posts

Posted - 2010-08-05 : 14:15:09
Hi I want to Execute

GRANT SELECT ON TableName TO [Domain\UserName]

in my ASP.net page ( in the .cs)

How can I give the [Domain\UserName] in the CommandText

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 14:43:34
http://bytes.com/topic/c-sharp/answers/214216-get-current-user-name-system

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

hemaljoes
Starting Member

7 Posts

Posted - 2010-08-05 : 15:16:19
What my requirement is to allow a top level users to grant permission to other users SELECT,INSERT,DELETE rights on a particular table

Thanks in advanced
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 15:17:53
Oh that's not what you had asked. You'll need to grant those users db_owner or db_ddladmin (I'm pretty sure GRANT is included here).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

hemaljoes
Starting Member

7 Posts

Posted - 2010-08-05 : 15:36:26
What i am asking is how to execute

GRANT SELECT ON TableName TO [Domain\UserName]

from a ASP.net page (Not from the SQL Server Management Studio)
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 15:40:26
You execute it the same as you would other statements. Can't you use ExecuteNonQuery or whatever it's called?

And to get the value of Domain\UserName, see the link I posted.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

hemaljoes
Starting Member

7 Posts

Posted - 2010-08-05 : 15:45:00
Explanation

I want to execute

GRANT SELECT ON TableName TO [Domain\UserName] from ASP.net page

in the ASP.net i create SqlConnection and a SqlCommand in SqlCommand's commandText i want to give the query i want to execute.

How could i give the [Domain\UserName]. Since [Domain\UserName] is a sysname object.

How can i make sysname object from a string such as 'Domain\UsernName' or is there any other way that i can accomplish my task
Go to Top of Page

hemaljoes
Starting Member

7 Posts

Posted - 2010-08-06 : 02:55:08
Sorry I think i haven't explain my problem clearly
Here what i need to do

I can successfully execute the following command from a ASP page

sqlCommand.CommandText = "CREATE LOGIN [DomainName\\UserName] FROM WINDOWS";
sqlCommand.ExecuteNonQuery();

But i want to execute something like below

sqlCommand.CommandText = "CREATE LOGIN ["+txtNewUser.Text+"] FROM WINDOWS";
sqlCommand.ExecuteNonQuery();

Thanks in advanced
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-06 : 12:33:27
Are you getting an error? If so, can you post it?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-06 : 13:18:51
quote:
Originally posted by hemaljoes

What i am asking is how to execute....from a ASP.net page (Not from the SQL Server Management Studio)



Why don't you think that this is not an extremely bad idea?

If you are trying to do grants from within an application, I'M SURE you are trying to create objects as well...

you need to separate the duties...and if your "app" is buil;t this way, then you are trying to build a silver bullet

Never have seen one work



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -