Last active
January 11, 2016 19:53
-
-
Save randyburden/d90576863cd13e294eb3 to your computer and use it in GitHub Desktop.
Inject Application Name Into ConnectionString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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