UtterAccess.com
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    
 
   
mojo
post Mar 6 2017, 05:23 AM
Post#1



Posts: 8
Joined: 7-August 13



Hello,

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.

CODE
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)
Else
NetworkUserName = vbNullString
End If

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



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


To return the login name:
SELECT SYSTEM_USER;
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:
SELECT 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
 
mojo
post Mar 6 2017, 07:21 AM
Post#3



Posts: 8
Joined: 7-August 13



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


Custom Search
RSSSearch   Top   Lo-Fi    19th August 2017 - 07:30 PM