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…

23 Comments to “Take Advantage of Application Name”

  1. Include Application Name in Your Connectionstring…

    You’ve been kicked (a good thing) – Trackback from DotNetKicks.com…

  2. [...] This post describes why you want to include your app name in the connection string to SQL Server.  Since we use a general connection string object to feed us different strings, our object would have to be modified to require a application name argument, but still looks useful for future debugging work. [...]

  3. Per says:

    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… :)

  4. Ben Griswold says:

    @Per – I’m glad you found the site (and the setting name.) Thanks for the feedback and validation.

  5. briggs says:

    A great secret of success is to go through life as a man who never gets used up.

  6. Rob says:

    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!

  7. Ben Griswold says:

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

  8. ???????? says:

    this is a great tip. i already used it for
    ???????? site.

  9. Kyralessa says:

    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.

  10. Ben Griswold says:

    @Kyralessa – That’s a very clever idea. Don’t change that Application Name! :)

  11. [...] On the final tab, you can provide extra connection information like Application Name which can come in handy.  [...]

  12. intzarali says:

    show the application no

  13. Erik says:

    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

  14. Ben Griswold says:

    @Erik, I love your comment. Thanks for helping to spread the word – one email at a time. :)

  15. [...] Take Advantage of Application NameSqlConnectionStringBuilder.ApplicationName Property Other « Commerce Server 2007 Capacity Planning Tool    VaryByCustom Caching By User » [...]

  16. ElMatador says:

    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

  17. Paul Barbin says:

    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.

  18. sim says:

    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.

  19. Ayush says:

    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

  20. JS says:

    select APP_NAME()

  21. hoangtxss says:

    Thank you so much!
    It’s helpful for me

  22. mariage says:

    Great post, I conceive blog owners should larn a lot from this weblog its really user pleasant. So much good info on here :D .

  23. Dudley Galli says:

    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.

Leave a Reply

You can wrap your code with [ruby][/ruby] or [python][/python] blocks for syntax highlighting and you can use these traditional tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>