Search code examples
nhibernateconnection-stringsql-server-profiler

How to customize the SQL Server connection ApplicationName property in Nhibernate for profiling


I am trying to correlate SQL query activity in a SQL Server Studio profile trace with different client processes in a large application that I am new to. The connection ApplicationName column in the trace window is set to ".Net SQLClient Data Provider" for all profiled query activity.

I would like to override the ApplicationName property on each new NHibernate command or connection with more meaningful internal application names associated with the main processes of the large application.

I have set a custom ApplicationName before but is it possible with NHibernate?


Solution

  • the first method I found was to use the connection-string (see links), but that is per connection and not per command and you won't know when .Net/NHibernate/Connection-Pooling/... decides to make a new connection.

    Change Application Name in Sql Server Profiler

    https://www.connectionstrings.com/use-application-name-sql-server/#:~:text=Simply%20include%20%22Application%20Name%3DMyAppName,%2C%20%22SELECT%20APP_NAME()%3B%22.

    I am trying to find an T-SQL-Command to change/set this value from within a connection, but wasn't lucky till now.

    Greetings

    Juy Juka