Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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