Re: apiGetUserName Lib "advapi32.dll"



Douglas,

Here is what I tried -
When I run the following query in 'Query Analyzer', I get the desired result -
select user, current_user, session_user,system_user


However, when I run the same in Acces Database I get error since it doesn't
recognize from where its supposed to retrieve the data.


So I linked the sysusers table and modified the query in Access as follows -

SELECT name, *
FROM sysusers
WHERE name=session_user;

It doesn't recognize session_user and it asks for session_user.

Do you have other suggestions?

Thank you,
-Me



"Douglas J. Steele" wrote:

You need to get that from SQL Server, not from WIndows.

You can create a pass-through query that retrieves the name from SQL Server.
Unfortunately, I can never remember which keyword you need to use: it's one
of USER_NAME, CURRENT_USER, SESSION_USER or SYSTEM_USER.

Go into SQL Server and run the following:

SELECT USER_NAME(), CURRENT_USER, SESSION_USER, SYSTEM_USER

Which of those 4 is what you're looking for?


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Me" <Me@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:539CD436-C0F1-4881-AE63-8900CE36EF4C@xxxxxxxxxxxxxxxx
I have a function apiGetUserName that uses - Lib "advapi32.dll"
to get me the username.

But this gets me the windows username with which I am logged on to the
computer.

I want to get the username with which I am logged on to SQL server
database.
Please note its not the access database login, but sql server login.

Thank you very much in advance,
-Me




.



Relevant Pages

  • Re: ODBC SQL Server Driver Timeout expired (#0) only in Access not
    ... Doug Steele, Microsoft Access MVP ... do a pass through query but then why use Access at all? ... into SQL view and cut and paste the same command into SQL Server ...
    (microsoft.public.access.modulesdaovba)
  • MS Query, SQL Server 7 and Office 2001
    ... I am using MS Query v9 which came as part of the Office 2001 Value ... I am using the SQL Server 7 driver which came as part of the Data ... should be prompted for a username and pssword to connect to the SQL ...
    (microsoft.public.mac.office.excel)
  • MS Query, SQL Server 7 and Office 2001
    ... I am using MS Query v9 which came as part of the Office 2001 Value ... I am using the SQL Server 7 driver which came as part of the Data ... should be prompted for a username and pssword to connect to the SQL ...
    (microsoft.public.mac.office)
  • Re: A tricky query
    ... > select username from user where region in ... > The problem is that I have to do this query from a user interface and call ... > stored procedure, in which the user can select multiple regions. ... > and be treated as one variable in SQL Server. ...
    (microsoft.public.sqlserver.programming)
  • Re: Oracle SQL Injection vulnerability
    ... The SELECT query doesn't seem to be the one you are injecting since ... likely what you put as a username is stored in a session object and is ... username field and injecting the password field with: ...
    (Pen-Test)

Loading