anthonypliu
anthonypliu

Reputation: 12437

How can I get a specific server identification programmatically

If I have multiple server nodes all linked to a database. I want to keep track of which transactions came from which server by adding a column in the table called "ServerName". Is there something I can do in c# to get the server name, mac address or something that I can put in that column that will uniquely identify which server the transaction came from when I save my data to the database table.

Upvotes: 2

Views: 76

Answers (2)

Ted
Ted

Reputation: 7271

System.Environment.MachineName should do the trick for you.

Upvotes: 0

John Koerner
John Koerner

Reputation: 38077

If you just want the computer name you can use the MachineName property of Environment class:

Environment.MachineName

Now there is no guarantee of uniqueness of this value as multiple machines can have the same name. For many environments though, this should be good enough.

You could get at the MAC address as well, if you want, but that may be overkill for your usage.

Upvotes: 2

Related Questions