SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


GET the windows or Operating System loginname using sql server 2005


GET the windows or Operating System loginname using sql server 2005

Author
Message
dakshinamurthy-655138
dakshinamurthy-655138
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1288 Visits: 1056
No,

my Pc or Laptop loginname is dakshina, where as i login to sql server using sa login and its password, the sql server may be either in my own pc or laptop or it might be in a different system or server .


With Regards
Dakshina Murthy
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)

Group: General Forum Members
Points: 95924 Visits: 38976
dakshinamurthy-655138 (4/19/2010)
No,

my Pc or Laptop loginname is dakshina, where as i login to sql server using sa login and its password, the sql server may be either in my own pc or laptop or it might be in a different system or server .


With Regards
Dakshina Murthy


Then you are out of luck. SQL Server has no way of determining who is logged in to a particular PC or Laptop directly. You may be able to write something using PowerShell that could possibly use WMI to query back to the PC or Laptop to determine who is logged in, but that is out of my current scope of knowledge.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Steve Jones
Steve Jones
SSC Guru
SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)

Group: Administrators
Points: 147847 Visits: 19441
Bhuvnesh (4/19/2010)
@Steve

Difference between suser_sname() and suser_name() ?


Not sure. I think there is a difference depending on your security connection and setup (AD v non-AD, group v user, etc.)

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Steve Jones
Steve Jones
SSC Guru
SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)SSC Guru (147K reputation)

Group: Administrators
Points: 147847 Visits: 19441
You are getting confused here about security context. When you log into SQL Server as "sa", SQL Server is a self-contained system. It has no knowledge, or even rights, to query your workstation. The only thing SQL Server has, and it can be changed, is the information that the driver sends. By default that's an app name, a workstation, etc. However those aren't necessarily correct. They can be overridden by someone making the connection.

While it's possible that you could make some query to get the workstation name, if you are using SQL authentication, SQL Server has no way to query on your behalf. Even an xp_cmdshell type query runs under the server context, so it can't go back and determine the logged in user.

Can I ask what you are trying to do?

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
dakshinamurthy-655138
dakshinamurthy-655138
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1288 Visits: 1056
Thanks for the support and information. Here i am trying to log the changes done for Database Objects from which system and which login the changes have been made.

Earliear we had the system name which was equal to my login name of the windows OS, but now the OS name is issys123 and loginname to log on to windows machine my desktop or laptop will be dakshina, hence i was trying to catch the loginname for the windows machine.


With Regards
Dakshina Murthy
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13424 Visits: 4077
dakshinamurthy-655138 (4/19/2010)
Here i am trying to log the changes done for Database Objects from which system and which login the changes have been made.
For this you can only use triggers and fetch the user name with
select suser_sname()

but for this; user needs to be connect with windows authentication. and for schema changes DDL trigger can help you.
For both windows authentication is must

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
dakshinamurthy-655138
dakshinamurthy-655138
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1288 Visits: 1056
Yes i was / am using a DDL Trigger, till now i was getting the system name like Hostname where i will get the computer name or pc or laptop name, but now as the name has changed to issys910 it is difficult to track whos system is that.
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13424 Visits: 4077
Whats the output for this in DDL trigger?
declare @data xml
set @data = EVENTDATA()
SELECT @data.value('(/EVENT_INSTANCE/LoginName)[1]', 'varchar(256)')



-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
dakshinamurthy-655138
dakshinamurthy-655138
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1288 Visits: 1056
Hi,

i am using like this

insert into dbo.changelog(databasename, eventtype,
objectname, objecttype, sqlcommand, loginname)
values(
@data.value('(/EVENT_INSTANCE/DatabaseName)[1]', 'varchar(256)'),
@data.value('(/EVENT_INSTANCE/EventType)[1]', 'varchar(50)'),
@data.value('(/EVENT_INSTANCE/ObjectName)[1]', 'varchar(256)'),
@data.value('(/EVENT_INSTANCE/ObjectType)[1]', 'varchar(25)'),
@data.value('(/EVENT_INSTANCE/TSQLCommand)[1]', 'varchar(max)'),
--@data.value('(/EVENT_INSTANCE/ServerName)[1]', 'varchar(256)')
Host_name()
)
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13424 Visits: 4077
First of all use windows authentication and then use the Sql code i posted in my last reply ( loginname) that can help you.


if still have any problem,post it.

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search