Get domain username

J

jez123456

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
 
M

Mary Chipman [MSFT]

If you log on to SQL Server using a SQL login, then SQL Server doesn't
know anything about the Windows domain/credentials of the calling
process. You will need to pass this information from your application
and persist it in SQL Server for that connection.

--Mary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top