tags:

views:

175

answers:

2

I have an app that run on many computers and connect to sql server I want to log the machine names of that computers in a table every time they connect how can I do that

I want to know if there is a command like that

"Select @@MachineName"

A: 

Create linked server : (allowing access to distributed, heterogeneous queries against OLE DB data sources.) using following command :

sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] [ , [ @provider= ] 'provider_name' ]

 [ , [ @datasrc= ] 'data_source' ] 
 [ , [ @location= ] 'location' ] 
 [ , [ @provstr= ] 'provider_string' ] 
 [ , [ @catalog= ] 'catalog' ]

Then access is like :

Select * from [server-name].[db-name].dbo.[tablename]

Also, make sure security login you are using on both the servers is same (or atleast exists on other server too).

Samiksha
+3  A: 

It's up to you how you want to log this information, but HOST_NAME() returns the name of the workstation connecting to the server.

Arnout