Take Advantage of Application Name

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…

Comments

  1. Pingback: DotNetKicks.com
  2. 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… :)

  3. 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!

  4. @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.

  5. Here’s another interesting use of Application Name:

    I’m working with a group on a localization project, and the DBA uses this to set the locale string (e.g. “en-US”).

    That way the locale setting is available, and localized strings can be returned, without having to pass in the locale with every query or stored proc.

  6. I hope people from work are reading this comment because that means they clicked on the link for this Blog in my email. :)

    Make DBA smile set APPLICATION NAME in your connection string.

    I am firm believer that this one setting can save an enterprise size company like ours many, many HOURS of time in a year, just from removing the time spent on figuring out where a SPID is coming from.

    Thanks!!

    Erik
    MCDBA, MCITP

  7. Thank you very much for this great tip.
    We are having problems with a few of our procedures, but, the DBA could not really identify what was causing it because there are different applications and processes that use the same db login.

    By providing the Application Name in the conn string, DBA is now able to tell what is being processed from our application and what is not.

    Thanks again!

    ElMatador

  8. We were considering using the ApplicationName as extended information regarding the end user when we have services connecting to the server (so we could filter our Profile by user).

    Just a word of caution there, however, as I believe this would essentially render Connection Pooling useless.

  9. wondering if Application name parameter is accessible after the connection is made, inside the queries.
    So if I have storeed procedure that can determine what application name is calling this SP, I can react differently.

  10. I am trying to use application name in SSAS connection string in SSIS package.
    When I run the package and I want to trace my connection using the query :”
    select connection_user_name,connection_host_application,connection_host_name from $system.discover_connections”
    The connection_host_application field comes out blank. Can you please let me know if there is a way I can get appliction name in above scenario?
    Thanks

  11. Hello, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam remarks? If so how do you prevent it, any plugin or anything you can recommend? I get so much lately it’s driving me crazy so any help is very much appreciated.

closed