Skip to content

Commit 34b9fa6

Browse files
dwallace0723jatinyadav-cc
authored andcommitted
✨ [source-mssql] skip sql server agent check if EngineEdition == 8 (airbytehq#35368)
1 parent 281d6c4 commit 34b9fa6

File tree

1 file changed

+21
-12
lines changed
  • airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql

1 file changed

+21
-12
lines changed

airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql/MssqlSource.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,27 @@ protected void assertCdcSchemaQueryable(final JsonNode config, final JdbcDatabas
417417
// todo: ensure this works for Azure managed SQL (since it uses different sql server agent)
418418
protected void assertSqlServerAgentRunning(final JdbcDatabase database) throws SQLException {
419419
try {
420-
final List<JsonNode> queryResponse = database.queryJsons(connection -> {
421-
final String sql =
422-
"SELECT status_desc FROM sys.dm_server_services WHERE [servicename] LIKE 'SQL Server Agent%' OR [servicename] LIKE 'SQL Server 代理%' ";
423-
final PreparedStatement ps = connection.prepareStatement(sql);
424-
LOGGER.info(String.format("Checking that the SQL Server Agent is running using the query: '%s'", sql));
425-
return ps;
426-
}, sourceOperations::rowToJson);
427-
428-
if (!(queryResponse.get(0).get("status_desc").toString().contains("Running"))) {
429-
throw new RuntimeException(String.format(
430-
"The SQL Server Agent is not running. Current state: '%s'. Please check the documentation on ensuring SQL Server Agent is running.",
431-
queryResponse.get(0).get("status_desc").toString()));
420+
// EngineEdition property values can be found at
421+
// https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16
422+
// SQL Server Agent is always running on SQL Managed Instance:
423+
// https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/transact-sql-tsql-differences-sql-server?view=azuresql#sql-server-agent
424+
final Integer engineEdition = database.queryInt("SELECT ServerProperty('EngineEdition')");
425+
if (engineEdition == 8) {
426+
LOGGER.info(String.format("SQL Server Agent is assumed to be running when EngineEdition == '%s'", engineEdition));
427+
} else {
428+
final List<JsonNode> queryResponse = database.queryJsons(connection -> {
429+
final String sql =
430+
"SELECT status_desc FROM sys.dm_server_services WHERE [servicename] LIKE 'SQL Server Agent%' OR [servicename] LIKE 'SQL Server 代理%' ";
431+
final PreparedStatement ps = connection.prepareStatement(sql);
432+
LOGGER.info(String.format("Checking that the SQL Server Agent is running using the query: '%s'", sql));
433+
return ps;
434+
}, sourceOperations::rowToJson);
435+
436+
if (!(queryResponse.get(0).get("status_desc").toString().contains("Running"))) {
437+
throw new RuntimeException(String.format(
438+
"The SQL Server Agent is not running. Current state: '%s'. Please check the documentation on ensuring SQL Server Agent is running.",
439+
queryResponse.get(0).get("status_desc").toString()));
440+
}
432441
}
433442
} catch (final Exception e) {
434443
if (e.getCause() != null && e.getCause().getClass().equals(com.microsoft.sqlserver.jdbc.SQLServerException.class)) {

0 commit comments

Comments
 (0)