Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [source-mssql] skip sql server agent check if EngineEdition == 8 #35368

Original file line number Diff line number Diff line change
Expand Up @@ -417,18 +417,23 @@ protected void assertCdcSchemaQueryable(final JsonNode config, final JdbcDatabas
// todo: ensure this works for Azure managed SQL (since it uses different sql server agent)
protected void assertSqlServerAgentRunning(final JdbcDatabase database) throws SQLException {
try {
final List<JsonNode> queryResponse = database.queryJsons(connection -> {
final String sql =
"SELECT status_desc FROM sys.dm_server_services WHERE [servicename] LIKE 'SQL Server Agent%' OR [servicename] LIKE 'SQL Server 代理%' ";
final PreparedStatement ps = connection.prepareStatement(sql);
LOGGER.info(String.format("Checking that the SQL Server Agent is running using the query: '%s'", sql));
return ps;
}, sourceOperations::rowToJson);

if (!(queryResponse.get(0).get("status_desc").toString().contains("Running"))) {
throw new RuntimeException(String.format(
"The SQL Server Agent is not running. Current state: '%s'. Please check the documentation on ensuring SQL Server Agent is running.",
queryResponse.get(0).get("status_desc").toString()));
final Int engineEdition = database.queryInt("SELECT ServerProperty('EngineEdition')");
dwallace0723 marked this conversation as resolved.
Show resolved Hide resolved
if (engineEdition == 8) {
LOGGER.info(String.format("Skipping check for whether SQL Server Agent is running. SQL Server Agent is assumed to be running when EngineEdition == '%s'"), engineEdition);
} else {
final List<JsonNode> queryResponse = database.queryJsons(connection -> {
final String sql =
"SELECT status_desc FROM sys.dm_server_services WHERE [servicename] LIKE 'SQL Server Agent%' OR [servicename] LIKE 'SQL Server 代理%' ";
final PreparedStatement ps = connection.prepareStatement(sql);
LOGGER.info(String.format("Checking that the SQL Server Agent is running using the query: '%s'", sql));
return ps;
}, sourceOperations::rowToJson);

if (!(queryResponse.get(0).get("status_desc").toString().contains("Running"))) {
throw new RuntimeException(String.format(
"The SQL Server Agent is not running. Current state: '%s'. Please check the documentation on ensuring SQL Server Agent is running.",
queryResponse.get(0).get("status_desc").toString()));
}
}
} catch (final Exception e) {
if (e.getCause() != null && e.getCause().getClass().equals(com.microsoft.sqlserver.jdbc.SQLServerException.class)) {
Expand Down
Loading