Capture Windows NT Login with Trigger function USER_NAME

Posted on 2007-10-05
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
    LVL 50

    Expert Comment

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

    Author Comment

    How do you have the database owned by SA?

    Also, can you elaborate on #2?
    LVL 50

    Accepted Solution

    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...

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now