Get domain username

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am using an Access ADP project which connects to SQL server using an SQL
login (GenLogin). My problem is obtaining a user’s individual domain login to
enter into an audit table.

Internally I can obtain the username using the following function

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = vbNullString
End If
End Function


This is fine for certain parts of my application; however, it is in the
audit trail where I have problems.

I have a table (AuditLog) which has a column (UserName) with the Default
Value set to suser_sname()

This works ok, but of course will always save the SQL Server login
(GenLogin) and not the individual username.

How can I set the UserName Default Value to use a function that is in the
vba code?

Is there a sql server user defined function that will return this?

Thanks for your help

.



Relevant Pages

  • Re: Index for username/password
    ... say that users want to be able to define customer ... A username in a login table is a little different. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: Get domain username
    ... login. ... My problem is obtaining a user’s individual domain login to ... audit trail where I have problems. ... I have a table which has a column (UserName) with the Default ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Get domain username
    ... If you log on to SQL Server using a SQL login, ... know anything about the Windows domain/credentials of the calling ... I have a table which has a column (UserName) with the Default ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Index for username/password
    ... > So if I later had an employee say, that needs to login, rather than add ... > a username,password to the Employee table I could simply add a LogonID ... The ID is superfluous when you have a natural key in the username. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: Login fails. Why?
    ... the 'UserName' login has not been granted access to the ... The user will need permissions on referenced database objects, ... SQL Server MVP ...
    (microsoft.public.sqlserver.security)