views:

30

answers:

2

i have this script:

BACKUP DATABASE timeclockplus TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\backup.bak'

how do i know which username is executing it? the reason i ask is because i want to grant extra privelages to the current username so that instead of writing that backup folder i can write to a different folder

+2  A: 

Take a look at SUSER_SNAME().

(That page is a bit misleading, passing no param returns the current user - either an SQL Logon or a domain\user depending on the auth mode)

Alex K.
+1 Not sure why anyone would downvote this :)
Andomar
@Andomar: Because it's wrong answer for this question which says "...instead of writing that backup folder i can write to a different folder". So it's about the SQL Service account, not the DB engine current user. And it's my downvote because of this. Unless you know something I don't about how SUSER_SNAME() relates to NFTS permissions
gbn
@gbn: Looks like you're right! Perhaps a comment to explain would be better than a downvote that looks puzzling at first sight :)
Andomar
+2  A: 

There is no context as such except for sa inside the DB engine.

Based on your recent questions, you mean external SQL Server context which will be the service account used (you can see it in Services.msc). So if you are using domain\Specialuser then you could permission domain\Specialuser on a folder.

However, SQL Server 2005 introduced some groups that should contain the service account specified at install time and these should be used for external (eg outside SQL Server) permissions

Some details in KB 283811 , but best seeing "Reviewing Windows NT Rights and Privileges Granted for SQL Server Service Accounts". The groups mentioned here are what you should permission on your desired folder.

gbn