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.
Asked
Active
Viewed 69 times
2
-
Note that in SQL Server you can use the "HOST_NAME()" function to get the name of the calling machine so you might not have to change your .Net code to get this information. – David Feb 07 '13 at 22:10
2 Answers
2
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.

Community
- 1
- 1

John Koerner
- 37,428
- 8
- 84
- 134