Anyone that works with SQL Server is bound to end up using SQL Server Profiler fairly often to see the SQL that’s getting executed. And anyone that’s used SQL Server Profiler will know about all the garbage that fills your trace view that you’d rather not know about. It’s at best a complete pain in the ass to browse through all of it to find anything relevant.
Today I noticed the ApplicationName column in the trace view and wondered what it was. Turns out that you can set an application name parameter in your connection string which shows up there.
Data Source=.\SQLEXPRESS;Initial Catalog=SomeDb;Integrated Security=True;Application Name=MyApp
What’s more, you can choose to filter what’s included in the trace based on the application name.
This makes the profiler much, much more usable. So usable in fact, that from now on I’ll probably have it open most of the time I’m developing!
Of course, there is a drawback, but only really a mild one. Connection pools are formed based on the uniqueness of connection strings, so if you have loads of applications accessing the same database server, and give them all unique application names then you may end up bloating the number of connections to SQL Server. However, the approach is certainly valuable for local development/diagnostics/testing.