473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Jul 20 '05 #1
5 7803
"William F. O'Neill" <wf******@bellsouth.net> wrote in message
news:Cl*********************@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()
Jul 20 '05 #2
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" <pa*******@yahoo.com> wrote in message
news:c8********************@adelphia.com...
"William F. O'Neill" <wf******@bellsouth.net> wrote in message
news:Cl*********************@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()

Jul 20 '05 #3
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
Jul 20 '05 #4
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" <wf******@bellsouth.net> wrote in message
news:Cl*********************@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.

Jul 20 '05 #5
Thanks for all the help, and suggestions.

"DHatheway" <dl********@mmm.com.nospam> wrote in message
news:ck*********@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" <wf******@bellsouth.net> wrote in message
news:Cl*********************@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.


Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher Weaver | last post by:
I want to set a value in a specific field in the current row of a DataSet. This seems like the most basic thing to do but I can't find the syntax for identifying the current row. IOW, I can do...
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
4
by: Dan Bart | last post by:
I am using an application which is a modification of IBuySpy Portal. It is using Forms authentication. Users login and their name is added to Context Then I use: ...
8
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
4
by: Leszek | last post by:
Hello! I have my webpage (ASP) in domain (IIS 6.0). I need to make a popup with fullname of current user. How can I do this? Maybe someone have any examples? Thanks!
0
by: davidr | last post by:
Hi, I been stuck on this for a week or more. So please help! I have a menu were a user can click a button and a user control is loaded into the page. A problem occurs when trying to load a...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
4
by: Doogie | last post by:
Hi, I am using HttpContext.Current.User.Identity.Name to get a user id from a web application. I then use that as part of a name of a cookie I'm writing. 30 minutes later I do a refresh of this...
9
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
13
by: bproddu | last post by:
Hi, I'm using Forms authentication for my web app. I've a custom Principal class that I would like to set to the HttpContext.Current.User after the Membership.ValidateUser() passes. I'm able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.