SQL Connection – Application Name

While at SQLBits, both Dave and Simon mentioned passing the Application name as part of the connection string to make debugging easier.  This was the first time I had heard this, so I decided to have a little look so I fired up my trusty linq to SQL Console and SQL Profiler and executed some queries.

Without using the application name parameter, SQL Profiler’s results looks like this.

image

From this, SSMS uses the parameter and you get a nice friendly name however my console application doesn’t and you get the information about the SqlClient data provider being used.  Helpful, if you only have one SqlClient running, unlikely if you have a production server.

If I modify my connection string and include the Application Name option as part of the connection string it would look like something below.

    connectionString=”Data Source=.;Initial Catalog=Northwind;Integrated Security=True;Application Name=LinqConsole
    providerName=”System.Data.SqlClient” />

Now if we execute the application, Sql Profiler uses the name in the connection string within the Application Name column. Much better and more useful!

image

But it’s not only in Sql Profiler where its used, if you execute sp_who2 to see which connections are made to the server you can see that the program name is include.  Very useful for detecting resource leaks…

image

If that wasn’t enough of a reason, then you can filter down which items are actually traced based on the application name.  When creating a new trace, simply go to Events Selection tab, select Column Filters and enter your application name in the Like (or Not Like) box.

image

I’m sure its used in many more places, however this was just a quick look at what it actually is and from now on I will definitely be including it in all my connection strings – it’s just good manners for anyone using or support your application.

Technorati Tags:

0 thoughts on “SQL Connection – Application Name

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>