Along with the SQL Server, Database, Username and Password, don’t forget to include the Application Name in your connection string. It’s an optional parameter, but it can be a lifesaver.
Data Source=myServer;
Initial Catalog=myDB;
User Id=myUsername;
Password=myPassword;
Application Name=myApp;
Consider this example: There are multiple .NET applications running on a single web server. Each application shares a common SQL Server Server which is suddenly performing very poorly. You are tasked with determine which of the applications is causing havoc. You launch SQL Profiler and run a trace. Since you have included the optional parameter in your connection string, you may now filter the application specific queries and troubleshoot the problem far more effectively. If you hadn’t specified the application name, you would have some work ahead of you. In this case, all of the queries would have had a generic app name, .NET sqlClient Data Provider, and that isn’t very helpful, is it?
Do yourself a favor and be sure to add this practice to your coding standards…
June 25th, 2009 at 9:52 pm
Agreed - I was googling to try to find out/verify the name of this setting, so I already knew about it. Guess why I’m setting it now? Exactly because I’m doing some SQL Server profiling…
June 26th, 2009 at 7:17 am
@Per - I’m glad you found the site (and the setting name.) Thanks for the feedback and validation.
November 23rd, 2009 at 11:01 am
A great secret of success is to go through life as a man who never gets used up.
January 26th, 2010 at 6:20 am
This is extreamly good practice to include an app name. I work at software support for a company and constantly need to set app names on connection strings as the original developers just didn’t bother! We run 50+ sites across two SQL Server DBs (current & legacy) and tracing procedure calls from most sites is almost impossible without updating the live web.config (which is horrendeously bad practice!)
There are also instances of app names being duplicated across multiple sites thanks to copy + paste so as you can imagine, it can get pretty frustrating!
January 26th, 2010 at 8:12 am
@Rob - Thanks for the comment. It’s really great to hear from folks who have been in the trenches and can really appreciate and endorse some of the tips I write about.
February 25th, 2010 at 5:15 am
this is a great tip. i already used it for
???????? site.