@@ -731,7 +731,32 @@ public final class SQLServerDriver implements java.sql.Driver {
731
731
static final String AUTH_DLL_NAME = "mssql-jdbc_auth-" + SQLJdbcVersion .MAJOR + "." + SQLJdbcVersion .MINOR + "."
732
732
+ SQLJdbcVersion .PATCH + "." + Util .getJVMArchOnWindows () + SQLJdbcVersion .RELEASE_EXT ;
733
733
static final String DEFAULT_APP_NAME = "Microsoft JDBC Driver for SQL Server" ;
734
+ static final String APP_NAME_TEMPLATE = "Microsoft JDBC - %s, %s - %s" ;
735
+ static final String constructedAppName ;
736
+ static {
737
+ constructedAppName = getAppName ();
738
+ }
734
739
740
+ /**
741
+ * Constructs the application name using system properties for OS, platform, and architecture.
742
+ * If any of the properties cannot be fetched, it falls back to the default application name.
743
+ * Format -> Microsoft JDBC - {OS}, {Platform} - {architecture}
744
+ *
745
+ * @return the constructed application name or the default application name if properties are not available
746
+ */
747
+ static String getAppName () {
748
+ String osName = System .getProperty ("os.name" , "" );
749
+ String osArch = System .getProperty ("os.arch" , "" );
750
+ String javaVmName = System .getProperty ("java.vm.name" , "" );
751
+ String javaVmVersion = System .getProperty ("java.vm.version" , "" );
752
+ String platform = javaVmName .isEmpty () || javaVmVersion .isEmpty () ? "" : javaVmName + " " + javaVmVersion ;
753
+
754
+ if (osName .isEmpty () && platform .isEmpty () && osArch .isEmpty ()) {
755
+ return DEFAULT_APP_NAME ;
756
+ }
757
+ return String .format (APP_NAME_TEMPLATE , osName , platform , osArch );
758
+ }
759
+
735
760
private static final String [] TRUE_FALSE = {"true" , "false" };
736
761
737
762
private static final SQLServerDriverPropertyInfo [] DRIVER_PROPERTIES = {
@@ -741,7 +766,7 @@ public final class SQLServerDriver implements java.sql.Driver {
741
766
SQLServerDriverStringProperty .APPLICATION_INTENT .getDefaultValue (), false ,
742
767
new String [] {ApplicationIntent .READ_ONLY .toString (), ApplicationIntent .READ_WRITE .toString ()}),
743
768
new SQLServerDriverPropertyInfo (SQLServerDriverStringProperty .APPLICATION_NAME .toString (),
744
- SQLServerDriverStringProperty .APPLICATION_NAME .getDefaultValue (), false , null ),
769
+ SQLServerDriverStringProperty .APPLICATION_NAME .getDefaultValue (), false , null ),
745
770
new SQLServerDriverPropertyInfo (SQLServerDriverStringProperty .COLUMN_ENCRYPTION .toString (),
746
771
SQLServerDriverStringProperty .COLUMN_ENCRYPTION .getDefaultValue (), false ,
747
772
new String [] {ColumnEncryptionSetting .DISABLED .toString (),
@@ -1028,6 +1053,9 @@ String getClassNameLogging() {
1028
1053
drLogger .finer ("Error registering driver: " + e );
1029
1054
}
1030
1055
}
1056
+ if (loggerExternal .isLoggable (Level .FINE )) {
1057
+ loggerExternal .log (Level .FINE , "Application Name: " + SQLServerDriver .constructedAppName );
1058
+ }
1031
1059
}
1032
1060
1033
1061
// Check for jdk.net.ExtendedSocketOptions to set TCP keep-alive options for idle connection resiliency
@@ -1266,6 +1294,9 @@ public java.sql.Connection connect(String url, Properties suppliedProperties) th
1266
1294
Properties connectProperties = parseAndMergeProperties (url , suppliedProperties );
1267
1295
if (connectProperties != null ) {
1268
1296
result = DriverJDBCVersion .getSQLServerConnection (toString ());
1297
+ if (connectProperties .getProperty (SQLServerDriverStringProperty .APPLICATION_NAME .toString ()) == null ) {
1298
+ connectProperties .setProperty (SQLServerDriverStringProperty .APPLICATION_NAME .toString (), SQLServerDriver .constructedAppName );
1299
+ }
1269
1300
result .connect (connectProperties , null );
1270
1301
}
1271
1302
loggerExternal .exiting (getClassNameLogging (), "connect" , result );
0 commit comments