Search code examples
.netsql-serverasp.net-corehostnamesql-server-2016

selecting HOST_NAME() triggered by application returns empty string


I have an ASP.Net Core application the connects to a SQL SERVER 2016 DB.
The application is updating a table and causing a logging trigger to take place.

One of the things that the trigger logs is the HOST_NAME().
Whenever I cause the trigger to run manually using SSMS (Sql Server Management Studio) the trigger acts as expected.
But whenever the application causes the trigger to run, the HOST_NAME() function logs an empty string to the logging table.

Is it something that should be set through code explicitly? Am I missing something?

Thanks!


Solution

  • HOST_NAME() just reports whatever was provided as the Workstation ID in the connection string. So, change your connection string (and also, be aware that its very easy for the server to be lied to, so don't rely on HOST_NAME() to make any security decisions)