Thursday, March 22, 2012

Current user

Am using SQL Server 2000, and am writing some audit triggers. How do I get
the the name of the user, eg. user_id or current_user. Just spent an hour
looking through the SAMS book for this, and can't find any reference."William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
> Am using SQL Server 2000, and am writing some audit triggers. How do I
> get the the name of the user, eg. user_id or current_user. Just spent an
> hour looking through the SAMS book for this, and can't find any reference.

select user_name()|||Thank you ParrotRob, but that gives me 'dbo.' If I log on to my
application, I want to be able to capture 'my' logon id, eg. wfoneill.
Remember, I want to be able to use this in my Insert, Update, & Delete
triggers.
Bill...

"ParrotRob" <parrotrob@.yahoo.com> wrote in message
news:c8udneeR2ZtXm_vcRVn-vQ@.adelphia.com...
> "William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
> news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
>> Am using SQL Server 2000, and am writing some audit triggers. How do I
>> get the the name of the user, eg. user_id or current_user. Just spent an
>> hour looking through the SAMS book for this, and can't find any
>> reference.
> select user_name()|||William F. O'Neill wrote:
> Am using SQL Server 2000, and am writing some audit triggers. How do
> I get the the name of the user, eg. user_id or current_user. Just
> spent an hour looking through the SAMS book for this, and can't find
> any reference.

You have:

CURRENT_USER
USER_NAME()
SUSER_SNAME()

If you get frustrated building audit triggers, you can look at our OmniAudit
product for doing exactly that:

http://www.krell-software.com/omniaudit

--
Steve Troxell|||The SAMS book is a good resource for learning how to user SQL Server but
isn't a great resource for looking things like this up. You can more
readily get the answer you need by getting familiar with SQL Server Books On
Line (BOL). Install or reinstall the tools on your desktop machine and load
all the documentation to your hard disk for best performance (and
availability). There is an option to use BOL off the CD but it will be
slower and whenever you want to use BOL, you'll have to remove your music CD
(and I just hate doing that).

Then, this problem will depend on how the users are connecting to the
database. If you're using an application UserID (where the credentials for
the connection are actually buried in the app and are the same for each
user), then you won't get much information about the individual who's
actually using the application. However, if you're using trusted
connections or you've set up SQL Server LogonIDs for each user, you could
see if:

select suser_sname()

- or -

select system_user

gives you the result you want. I think there are also some global variables
that you could examine to see if they'll help you.

Really, time spent in BOL getting familiar with how to find things is not
time wasted. Remember that whenever you hit a topic, you should check the
"See Also" list at the bottom of each page.

"William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
> Am using SQL Server 2000, and am writing some audit triggers. How do I
get
> the the name of the user, eg. user_id or current_user. Just spent an hour
> looking through the SAMS book for this, and can't find any reference.|||Thanks for all the help, and suggestions.

"DHatheway" <dlhatheway@.mmm.com.nospam> wrote in message
news:ck67rd$qc$1@.tuvok3.mmm.com...
> The SAMS book is a good resource for learning how to user SQL Server but
> isn't a great resource for looking things like this up. You can more
> readily get the answer you need by getting familiar with SQL Server Books
> On
> Line (BOL). Install or reinstall the tools on your desktop machine and
> load
> all the documentation to your hard disk for best performance (and
> availability). There is an option to use BOL off the CD but it will be
> slower and whenever you want to use BOL, you'll have to remove your music
> CD
> (and I just hate doing that).
> Then, this problem will depend on how the users are connecting to the
> database. If you're using an application UserID (where the credentials
> for
> the connection are actually buried in the app and are the same for each
> user), then you won't get much information about the individual who's
> actually using the application. However, if you're using trusted
> connections or you've set up SQL Server LogonIDs for each user, you could
> see if:
> select suser_sname()
> - or -
> select system_user
> gives you the result you want. I think there are also some global
> variables
> that you could examine to see if they'll help you.
> Really, time spent in BOL getting familiar with how to find things is not
> time wasted. Remember that whenever you hit a topic, you should check the
> "See Also" list at the bottom of each page.
> "William F. O'Neill" <wfoneill@.bellsouth.net> wrote in message
> news:Clg9d.183017$Np2.110030@.bignews4.bellsouth.ne t...
>> Am using SQL Server 2000, and am writing some audit triggers. How do I
> get
>> the the name of the user, eg. user_id or current_user. Just spent an
>> hour
>> looking through the SAMS book for this, and can't find any reference.
>>
>>

No comments:

Post a Comment