Skip to content

Commit 60296eb

Browse files
authored
Revert "Capture Client Guest OS and architecture in JDBC (#2561)"
This reverts commit 565ee02.
1 parent 74a5cb8 commit 60296eb

File tree

3 files changed

+2
-69
lines changed

3 files changed

+2
-69
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2446,7 +2446,7 @@ Connection connectInternal(Properties propsIn,
24462446
if (null != sPropValue)
24472447
validateMaxSQLLoginName(sPropKey, sPropValue);
24482448
else
2449-
activeConnectionProperties.setProperty(sPropKey, SQLServerDriver.constructedAppName);
2449+
activeConnectionProperties.setProperty(sPropKey, SQLServerDriver.DEFAULT_APP_NAME);
24502450

24512451
sPropKey = SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString();
24522452
sPropValue = activeConnectionProperties.getProperty(sPropKey);

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java

+1-30
Original file line numberDiff line numberDiff line change
@@ -731,32 +731,7 @@ public final class SQLServerDriver implements java.sql.Driver {
731731
static final String AUTH_DLL_NAME = "mssql-jdbc_auth-" + SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR + "."
732732
+ SQLJdbcVersion.PATCH + "." + Util.getJVMArchOnWindows() + SQLJdbcVersion.RELEASE_EXT;
733733
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-
}
739734

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-
760735
private static final String[] TRUE_FALSE = {"true", "false"};
761736

762737
private static final SQLServerDriverPropertyInfo[] DRIVER_PROPERTIES = {
@@ -766,7 +741,7 @@ static String getAppName() {
766741
SQLServerDriverStringProperty.APPLICATION_INTENT.getDefaultValue(), false,
767742
new String[] {ApplicationIntent.READ_ONLY.toString(), ApplicationIntent.READ_WRITE.toString()}),
768743
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.APPLICATION_NAME.toString(),
769-
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), false, null),
744+
SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), false, null),
770745
new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.COLUMN_ENCRYPTION.toString(),
771746
SQLServerDriverStringProperty.COLUMN_ENCRYPTION.getDefaultValue(), false,
772747
new String[] {ColumnEncryptionSetting.DISABLED.toString(),
@@ -1053,9 +1028,6 @@ String getClassNameLogging() {
10531028
drLogger.finer("Error registering driver: " + e);
10541029
}
10551030
}
1056-
if (loggerExternal.isLoggable(Level.FINE)) {
1057-
loggerExternal.log(Level.FINE, "Application Name: " + SQLServerDriver.constructedAppName);
1058-
}
10591031
}
10601032

10611033
// Check for jdk.net.ExtendedSocketOptions to set TCP keep-alive options for idle connection resiliency
@@ -1294,7 +1266,6 @@ public java.sql.Connection connect(String url, Properties suppliedProperties) th
12941266
Properties connectProperties = parseAndMergeProperties(url, suppliedProperties);
12951267
if (connectProperties != null) {
12961268
result = DriverJDBCVersion.getSQLServerConnection(toString());
1297-
connectProperties.setProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString(), SQLServerDriver.constructedAppName);
12981269
result.connect(connectProperties, null);
12991270
}
13001271
loggerExternal.exiting(getClassNameLogging(), "connect", result);

src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java

-38
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import static org.junit.Assert.fail;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
5-
import static org.junit.jupiter.api.Assertions.assertFalse;
6-
import static org.junit.jupiter.api.Assertions.assertNotNull;
75
import static org.junit.jupiter.api.Assertions.assertTrue;
86

97
import java.sql.Connection;
@@ -192,40 +190,4 @@ public void testConnectionDriver() throws SQLException {
192190
}
193191
}
194192
}
195-
196-
/**
197-
* test application name
198-
*
199-
* @throws SQLException
200-
*/
201-
@Test
202-
public void testApplicationName() throws SQLException {
203-
try (Connection conn = DriverManager.getConnection(connectionString);
204-
Statement stmt = conn.createStatement();
205-
ResultSet rs = stmt.executeQuery("SELECT program_name FROM sys.dm_exec_sessions WHERE session_id = @@SPID")) {
206-
if (rs.next()) {
207-
assertEquals(SQLServerDriver.constructedAppName, rs.getString("program_name"));
208-
}
209-
} catch (SQLException e) {
210-
fail(e.getMessage());
211-
}
212-
}
213-
214-
/**
215-
* test application name when system properties are empty
216-
*
217-
*/
218-
@Test
219-
public void testGetAppName() {
220-
String appName = SQLServerDriver.getAppName();
221-
assertNotNull(appName, "Application name should not be null");
222-
assertFalse(appName.isEmpty(), "Application name should not be empty");
223-
224-
System.setProperty("os.name", "");
225-
System.setProperty("os.arch", "");
226-
System.setProperty("java.vm.name", "");
227-
System.setProperty("java.vm.version", "");
228-
String defaultAppName = SQLServerDriver.getAppName();
229-
assertEquals(SQLServerDriver.DEFAULT_APP_NAME, defaultAppName, "Application name should be the default one");
230-
}
231193
}

0 commit comments

Comments
 (0)