Learn how to a build a cloud-first strategyRegister Now


Capture Windows NT Login with Trigger function USER_NAME

Posted on 2007-10-05
Medium Priority
Last Modified: 2010-04-23
I am developing an application in Visual Studio 2003 .NET and using a SQL Server database backend.

I created a Trigger to monitor a table. When records are inserted into this table the Trigger will create an entry in an Audit table for reference. I am using the USER_NAME() function within the Trigger to try and capture the users WINDOWS NT LOGIN NAME. The Trigger is firing however the USER_NAME function is returning "dbo" instead of the users' WINDOWS NT LOGIN NAME.

In my application I am using the following to Insert the record.

        Dim strSQL As String
        Dim cnSQL As SqlConnection
        Dim cmSQL As SqlCommand

        strSQL = "......."

        cnSQL = New SqlConnection(appOptions.ConnectionString)
        cmSQL = New SqlCommand(strSQL, cnSQL)

How can I capture the user's WINDOWS NT LOGIN NAME?
Question by:lloyd36
  • 2
LVL 50

Expert Comment

ID: 20023446
1) have the database owned by SA
2) have separate ids for you as a user and as a DBA...

Author Comment

ID: 20023819
How do you have the database owned by SA?

Also, can you elaborate on #2?
LVL 50

Accepted Solution

Lowfatspread earned 200 total points
ID: 20035332
1 exec sp_changedbowner 'SA'

2 you need to separate your functional use of the systems....

    when performing your role as a DBA ... have one id

    when performing a use role have a different id...

   In normal cases it is assumed that you do not perform a combined role...


Expert Comment

ID: 20237775
Forced accept.

EE Admin

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question