Include Application Name in Connection Strings

In addition to the SQL Server, Database, User ID and Password, you may want to include the Application Name in your connection string parameters. Application Name is an optional argument, but it can greatly help you to segregate the SQL that your application is executing from any other database calls that are being sent from other applications/processes.

Data Source=myServer;
Initial Catalog=myDB;
User Id=myUsername;
Application Name=myApp;

In example:

When there are multiple .NET applications sharing a common SQL Server. In the case that the SQL Server starts to show poor performance, you or a dba may be tasked with figuring out which of the applications is causing the slow performance. If you are using SQL Profiler to run a trace, and if you include the optional parameter in your connection string, you will be able to filter the application specific dB calls and it will make it a LOT easier to effectively troubleshoot the problem.

Without specifying the application name, it will be very difficult to isolate the application that is the source of the poor performance problem. Because all of the dB calls that do NOT specify an Application Name will show a generic ".NET sqlClient Data Provider" as the source of the queries. This will not help you at all to identify the source of the problem.

It makes sense, then, that best practice dictates to include this optional argument in all of your connection strings.

2 responses to “Include Application Name in Connection Strings”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.