Archive

Posts Tagged ‘sql function’

Using Built-in System Function – HOST_NAME()

26.05.2011 No comments

You can use the HOST_NAME() function to get the client workstation name from which the query is executed.

You can use it as:

— © 2011 – Vishal (http://SqlAndMe.com)

 

SELECT @@SERVERNAME, HOST_NAME()

Result Set:

——————- ——————-

VGAJJAR             VGAJJAR

 

(1 row(s) affected)

Same query executed from different machine gives the result:

——————- ——————-

VGAJJAR             VGAJJAR2

 

(1 row(s) affected)

However, HOST_NAME() function can not be used as a security feature, because client application can set the workstation name in a connection string, using WSID keyword.

For example,

image

Now, check the result again:

— © 2011 – Vishal (http://SqlAndMe.com)

 

SELECT @@SERVERNAME, HOST_NAME()

Result Set:

——————- ——————-

VGAJJAR             SERVER01

 

(1 row(s) affected)

Another useful function to know is HOST_ID() – which can be used to get the client process ID.

Hope This Helps!

Vishal