X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Capture SQL Server Login Credentials, Access 2010    
post Mar 6 2017, 05:23 AM

Posts: 8
Joined: 7-August 13


I've been using the code below to capture the username of the person logged in to the a PC. This works fine as far as it goes.

In an Access .adp database is it possible to capture the name of the user who's logging in to SQL Server, rather than the local computer username?

Thanks for any help.

Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Internal file reference for getting Windows username

Function NetworkUserName() As String
'Initialise variables
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
NetworkUserName = Left$(strUserName, lngLen - 1)
NetworkUserName = vbNullString
End If

End Function
Go to the top of the page
post Mar 6 2017, 06:04 AM

Posts: 839
Joined: 26-January 14
From: London, UK

To return the login name:
If you are using integrated security (which is highly recommended) then this would be the same login name you use to login to your client PC. If you are using SQL Server logins then the login name returned is the SQL Server login name rather than your Windows login.

To return the user name:

Login name and user name may be different if you have set up named users in the database.
Go to the top of the page
post Mar 6 2017, 07:21 AM

Posts: 8
Joined: 7-August 13

Thanks for your reply.
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    22nd March 2018 - 06:33 PM