SQL Server Performance

NetWork user name - logged user

Discussion in 'General DBA Questions' started by sunda, May 16, 2009.

  1. sunda New Member

    Hello all!
    Does anyone knows how a function in sql server 2000 to get the windows user name (from the one ho is logged)? this is for me to do the log.
    thanks a lot, again.
  2. madhuottapalam New Member

    check if SYSTEM_USER Function is that you are looking for.
    select
    system_user
    Madhu
  3. sunda New Member

    Thank you,
    But it is not this yet. What i need is for exemple: i turn on my computer, in my work then i log on in the windows. ex.: login: sunda, password: sunda. then my windows will start, and only after all of it i will enter in sql query analyser to type my login and password, wich can be diferent from the windows. What i need is the windows user logged.
    Thanks all again for the help!
  4. MohammedU New Member

    Then you have to choose windows authentication which will allow you to login...
    If you choose sql authentication then you have to enter again user name and pwd..
  5. FrankKalis Moderator

    If you log in via SQL authentication, how should SQL Server be able to find the associated Windows login?
    Anyway, you might be able to get this via the undocumented xp_instance_regread extended procedure.
  6. sunda New Member

    So, my teachers friends,
    There are some languages ho can get this informations, like foxpro, vb, etc, because they uses windows dlls. Like SQL Server these are also microsoft programs, that is why i thought the sql server could get the information.
    Anyway, i think there are a friend of mine ho did this in sql server. I will continue to look for it and if i find, i will post the answer in this same topic.
    Thanks again for the help!
  7. Adriaan New Member

    SQL can call the Windows command line like this ...
    exec master..xp_cmdshell 'echo %username%'
    ... but this will be executed on the computer on which SQL is running - which is usually a server, and not your workstation.
    As suggested above, you would not have a problem if you were using Windows authentication.
    If Windows authentication is not an option, then the information needs to come from the client application that is accessing SQL Server.
  8. FrankKalis Moderator

    [quote user="Adriaan"]
    If Windows authentication is not an option, then the information needs to come from the client application that is accessing SQL Server.
    [/quote]
    Which is a quite common scenario when using Web applications... [:)]
  9. sunda New Member

    ok, i got it! anyway i will continue to look and i will give u a feedback if i find the answer. The fact of sql server not be a program language is cause me a lot of troble. I would like to work wich separete concepts, for exemple, application, db and business. This way i could change all my application without suffer nothing o business or db, and so on, but if the db is limited for this kind of use i will have some dependency alter all.
    thanks!
  10. FrankKalis Moderator

    [quote user="sunda"]
    There are some languages ho can get this informations, like foxpro, vb, etc, because they uses windows dlls. Like SQL Server these are also microsoft programs, that is why i thought the sql server could get the information.
    [/quote]
    As I mentioned you can get this information by using either your own CLR code (provided that you use SQL Server 2005 and above) or use something undocumented like the xp_regread procedure. Doesn't have anything to do with SQL Server being a Microsoft product or not. It it primarily a database management system, not a programming language.

Share This Page