Skip to content

Instantly share code, notes, and snippets.

@randyburden
Last active January 11, 2016 19:53
Show Gist options
  • Save randyburden/d90576863cd13e294eb3 to your computer and use it in GitHub Desktop.
Save randyburden/d90576863cd13e294eb3 to your computer and use it in GitHub Desktop.
Inject Application Name Into ConnectionString
public string GetConnectionString( string connectionStringName, string applicationName )
{
var connectionString = ConfigurationManager.ConnectionStrings[ connectionStringName ];
var builder = new System.Data.SqlClient.SqlConnectionStringBuilder( connectionString );
// Inject application name into connection string
if ( String.IsNullOrWhiteSpace( builder.ApplicationName ) )
{
if ( String.IsNullOrWhiteSpace( applicationName ) == false )
{
builder.ApplicationName = applicationName;
}
}
return builder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment