diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index be4df3139..f5e6bc317 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -2615,7 +2615,7 @@ Connection connectInternal(Properties propsIn, if (null != sPropValue) validateMaxSQLLoginName(sPropKey, sPropValue); else - activeConnectionProperties.setProperty(sPropKey, SQLServerDriver.constructedAppName); + activeConnectionProperties.setProperty(sPropKey, SQLServerDriver.DEFAULT_APP_NAME); sPropKey = SQLServerDriverBooleanProperty.LAST_UPDATE_COUNT.toString(); sPropValue = activeConnectionProperties.getProperty(sPropKey); @@ -6892,7 +6892,8 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ String sPwd = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString()); String appName = activeConnectionProperties .getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString()); - String interfaceLibName = "Microsoft JDBC Driver " + SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR; + String interfaceLibName = "Microsoft JDBC Driver " + SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR; + //String interfaceLibName = SQLServerDriver.constructedAppName; String databaseName = activeConnectionProperties .getProperty(SQLServerDriverStringProperty.DATABASE_NAME.toString()); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java index 1f3c7993b..61b9f8f0c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java @@ -170,7 +170,7 @@ public void setApplicationName(String applicationName) { @Override public String getApplicationName() { return getStringProperty(connectionProps, SQLServerDriverStringProperty.APPLICATION_NAME.toString(), - SQLServerDriver.constructedAppName); + SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue()); } /** diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java index 17264ce59..a265d8099 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java @@ -738,11 +738,11 @@ public final class SQLServerDriver implements java.sql.Driver { static final String AUTH_DLL_NAME = "mssql-jdbc_auth-" + SQLJdbcVersion.MAJOR + "." + SQLJdbcVersion.MINOR + "." + SQLJdbcVersion.PATCH + "." + Util.getJVMArchOnWindows() + SQLJdbcVersion.RELEASE_EXT; static final String DEFAULT_APP_NAME = "Microsoft JDBC Driver for SQL Server"; - static final String APP_NAME_TEMPLATE = "Microsoft JDBC - %s, %s - %s"; - static final String constructedAppName; - static { - constructedAppName = getAppName(); - } + // static final String APP_NAME_TEMPLATE = "Microsoft JDBC - %s, %s - %s"; + // static final String constructedAppName; + // static { + // constructedAppName = getAppName(); + // } /** * Constructs the application name using system properties for OS, platform, and architecture. @@ -751,18 +751,18 @@ public final class SQLServerDriver implements java.sql.Driver { * * @return the constructed application name or the default application name if properties are not available */ - static String getAppName() { - String osName = System.getProperty("os.name", ""); - String osArch = System.getProperty("os.arch", ""); - String javaVmName = System.getProperty("java.vm.name", ""); - String javaVmVersion = System.getProperty("java.vm.version", ""); - String platform = javaVmName.isEmpty() || javaVmVersion.isEmpty() ? "" : javaVmName + " " + javaVmVersion; - - if (osName.isEmpty() && platform.isEmpty() && osArch.isEmpty()) { - return DEFAULT_APP_NAME; - } - return String.format(APP_NAME_TEMPLATE, osName, platform, osArch); - } + // static String getAppName() { + // String osName = System.getProperty("os.name", ""); + // String osArch = System.getProperty("os.arch", ""); + // String javaVmName = System.getProperty("java.vm.name", ""); + // String javaVmVersion = System.getProperty("java.vm.version", ""); + // String platform = javaVmName.isEmpty() || javaVmVersion.isEmpty() ? "" : javaVmName + " " + javaVmVersion; + + // if (osName.isEmpty() && platform.isEmpty() && osArch.isEmpty()) { + // return DEFAULT_APP_NAME; + // } + // return String.format(APP_NAME_TEMPLATE, osName, platform, osArch); + // } private static final String[] TRUE_FALSE = {"true", "false"}; @@ -1073,9 +1073,9 @@ String getClassNameLogging() { drLogger.finer("Error registering driver: " + e); } } - if (loggerExternal.isLoggable(Level.FINE)) { - loggerExternal.log(Level.FINE, "Application Name: " + SQLServerDriver.constructedAppName); - } + // if (loggerExternal.isLoggable(Level.FINE)) { + // loggerExternal.log(Level.FINE, "Application Name: " + SQLServerDriver.constructedAppName); + // } } // Check for jdk.net.ExtendedSocketOptions to set TCP keep-alive options for idle connection resiliency @@ -1314,9 +1314,9 @@ public java.sql.Connection connect(String url, Properties suppliedProperties) th Properties connectProperties = parseAndMergeProperties(url, suppliedProperties); if (connectProperties != null) { result = DriverJDBCVersion.getSQLServerConnection(toString()); - if (connectProperties.getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString()) == null) { - connectProperties.setProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString(), SQLServerDriver.constructedAppName); - } + // if (connectProperties.getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString()) == null) { + // connectProperties.setProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString(), SQLServerDriver.constructedAppName); + // } result.connect(connectProperties, null); } loggerExternal.exiting(getClassNameLogging(), "connect", result); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java index 646ad75e9..be9333e24 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/SQLServerDriverTest.java @@ -204,7 +204,7 @@ public void testApplicationName() throws SQLException { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT program_name FROM sys.dm_exec_sessions WHERE session_id = @@SPID")) { if (rs.next()) { - assertEquals(SQLServerDriver.constructedAppName, rs.getString("program_name")); + assertEquals(SQLServerDriverStringProperty.APPLICATION_NAME.getDefaultValue(), rs.getString("program_name")); } } catch (SQLException e) { fail(e.getMessage()); @@ -216,54 +216,54 @@ public void testApplicationName() throws SQLException { * * @throws SQLException */ - @Test - public void testApplicationNameUsingApp_Name() throws SQLException { - try (Connection conn = DriverManager.getConnection(connectionString); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT app_name()")) { - if (rs.next()) { - assertEquals(SQLServerDriver.constructedAppName, rs.getString(1)); - } - } catch (SQLException e) { - fail(e.getMessage()); - } - } + // @Test + // public void testApplicationNameUsingApp_Name() throws SQLException { + // try (Connection conn = DriverManager.getConnection(connectionString); + // Statement stmt = conn.createStatement(); + // ResultSet rs = stmt.executeQuery("SELECT app_name()")) { + // if (rs.next()) { + // assertEquals(SQLServerDriver.constructedAppName, rs.getString(1)); + // } + // } catch (SQLException e) { + // fail(e.getMessage()); + // } + // } /** * test application name by executing select app_name() * * @throws SQLException */ - @Test - public void testAppNameWithSpecifiedApplicationName() throws SQLException { - String url = connectionString + ";applicationName={0123456789012345678901234567890123456789012345678901234567890123456789012345678901234589012345678901234567890123456789012345678}"; + // @Test + // public void testAppNameWithSpecifiedApplicationName() throws SQLException { + // String url = connectionString + ";applicationName={0123456789012345678901234567890123456789012345678901234567890123456789012345678901234589012345678901234567890123456789012345678}"; - try (Connection conn = DriverManager.getConnection(url); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT app_name()")) { - if (rs.next()) { - assertEquals("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234589012345678901234567890123456789012345678", rs.getString(1)); - } - } catch (SQLException e) { - fail(e.getMessage()); - } - } + // try (Connection conn = DriverManager.getConnection(url); + // Statement stmt = conn.createStatement(); + // ResultSet rs = stmt.executeQuery("SELECT app_name()")) { + // if (rs.next()) { + // assertEquals("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234589012345678901234567890123456789012345678", rs.getString(1)); + // } + // } catch (SQLException e) { + // fail(e.getMessage()); + // } + // } /** * test application name when system properties are empty * */ - @Test - public void testGetAppName() { - String appName = SQLServerDriver.getAppName(); - assertNotNull(appName, "Application name should not be null"); - assertFalse(appName.isEmpty(), "Application name should not be empty"); + // @Test + // public void testGetAppName() { + // String appName = SQLServerDriver.getAppName(); + // assertNotNull(appName, "Application name should not be null"); + // assertFalse(appName.isEmpty(), "Application name should not be empty"); - System.setProperty("os.name", ""); - System.setProperty("os.arch", ""); - System.setProperty("java.vm.name", ""); - System.setProperty("java.vm.version", ""); - String defaultAppName = SQLServerDriver.getAppName(); - assertEquals(SQLServerDriver.DEFAULT_APP_NAME, defaultAppName, "Application name should be the default one"); - } + // System.setProperty("os.name", ""); + // System.setProperty("os.arch", ""); + // System.setProperty("java.vm.name", ""); + // System.setProperty("java.vm.version", ""); + // String defaultAppName = SQLServerDriver.getAppName(); + // assertEquals(SQLServerDriver.DEFAULT_APP_NAME, defaultAppName, "Application name should be the default one"); + // } }