@@ -193,27 +193,31 @@ def _fetch_for_databases(self):
193
193
engine_edition = self ._check .static_info_cache .get (STATIC_INFO_ENGINE_EDITION )
194
194
with self ._check .connection .open_managed_default_connection ():
195
195
with self ._check .connection .get_managed_cursor () as cursor :
196
- for db_name in databases :
197
- try :
198
- if not is_azure_sql_database (engine_edition ):
199
- cursor .execute (SWITCH_DB_STATEMENT .format (db_name ))
200
- self ._fetch_schema_data (cursor , start_time , db_name )
201
- except StopIteration as e :
202
- self ._log .error (
203
- "While executing fetch schemas for databse {}, the following exception occured {}" .format (
204
- db_name , e
196
+ try :
197
+ for db_name in databases :
198
+ try :
199
+ if not is_azure_sql_database (engine_edition ):
200
+ cursor .execute (SWITCH_DB_STATEMENT .format (db_name ))
201
+ self ._fetch_schema_data (cursor , start_time , db_name )
202
+ except StopIteration as e :
203
+ self ._log .error (
204
+ """While executing fetch schemas for databse {},
205
+ the following exception occured {}""" .format (
206
+ db_name , e
207
+ )
205
208
)
206
- )
207
- return
208
- except Exception as e :
209
- self ._log .error (
210
- "While executing fetch schemas for databse {}, the following exception occured {}" .format (
211
- db_name , e
209
+ break
210
+ except Exception as e :
211
+ self ._log .error (
212
+ """While executing fetch schemas for databse {},
213
+ the following exception occured {}""" .format (
214
+ db_name , e
215
+ )
212
216
)
213
- )
214
- # Switch DB back to MASTER
215
- if not is_azure_sql_database (engine_edition ):
216
- cursor .execute (SWITCH_DB_STATEMENT .format (self ._check .connection .DEFAULT_DATABASE ))
217
+ finally :
218
+ # Switch DB back to MASTER
219
+ if not is_azure_sql_database (engine_edition ):
220
+ cursor .execute (SWITCH_DB_STATEMENT .format (self ._check .connection .DEFAULT_DATABASE ))
217
221
218
222
@tracked_method (agent_check_getter = agent_check_getter )
219
223
def _collect_schemas_data (self ):
0 commit comments