@@ -417,18 +417,27 @@ protected void assertCdcSchemaQueryable(final JsonNode config, final JdbcDatabas
417
417
// todo: ensure this works for Azure managed SQL (since it uses different sql server agent)
418
418
protected void assertSqlServerAgentRunning (final JdbcDatabase database ) throws SQLException {
419
419
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
+ }
432
441
}
433
442
} catch (final Exception e ) {
434
443
if (e .getCause () != null && e .getCause ().getClass ().equals (com .microsoft .sqlserver .jdbc .SQLServerException .class )) {
0 commit comments