[dba-SQLServer]Connection String

Francisco H Tapia my.lists at verizon.net
Thu Apr 3 16:31:07 CST 2003


If you are using windows authentication then you can just use this.
otherwise if you are using sql authentication you'll need to parse the
string.

'Use the following to get UserName
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

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 = ""
    End If
End Function

-Francisco
http://rcm.netfirms.com

On Thursday, April 03, 2003 2:15 PM [GMT-8],
David Emerson <davide at dalyn.co.nz> wrote:

: AXP ADP/SQL2000.
:
: I can get the current Connection string by using
: CurrentProject.Connection.ConnectionString.
:
: I want to be able to check the current user (User ID = xxx) and run
: code based on who it is.  Is there a simple function to find out the
: User or do I have to do string manipulation on the ConnectionString?
:
: Regards
:
: David Emerson
: DALYN Software Ltd
: 25b Cunliffe St, Johnsonville
: Wellington, New Zealand
: Ph/Fax (877) 456-1205
:
: _______________________________________________
: dba-SQLServer mailing list
: dba-SQLServer at databaseadvisors.com
: http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
: http://www.databaseadvisors.com




More information about the dba-SQLServer mailing list