Search code examples
advantage-database-serversystem-procedures

How to define a current user?


Is it possible to define a current user?

I found a stored procedure 'sp_mgGetConnectedUsers'. It returns a result set with the only unique field 'Address'. How could I associate an executing query with such 'Address'.

Please advice.

Note: As far as I understand, another way to get the current user is to set a unique application Id for each connection, but I don't like this way much.


Solution

  • If using a data dictionary you can use the user scalar function:

    select user() from system.iota;
    

    and correlate that with the DictionaryUser field returned from sp_mgGetConnectedUsers.

    If not using a dictionary the easiest way would be to use the sp_SetApplicationID and sp_GetApplicationID. Why don't you like that way? It might be easier to help you if we knew what your final goal was. If you just want to see the user associated with a query, execute the sp_GetSQLStatements procedure.