@@ -143,6 +143,7 @@ class ConnectionManager:
143143 def __init__ (self ):
144144 self .omit_trailing_semicolon : bool = False
145145 self .connection_store : ConnectionStore = ConnectionStore ()
146+ self .ibmdb_driver_already_added_to_path : bool = False
146147
147148 @staticmethod
148149 def _hide_password_values (string_with_pass , params_separator = "," ):
@@ -320,18 +321,20 @@ def _arg_or_config(arg_value, param_name, *, old_param_name=None, mandatory=Fals
320321
321322 if db_api_module_name in ["ibm_db" , "ibm_db_dbi" ]:
322323 if os .name == "nt" :
323- spec = importlib .util .find_spec (db_api_module_name )
324- if spec is not None :
325- logger .info (
326- f"Importing DB module '{ db_api_module_name } ' on Windows requires configuring the DLL directory for CLI driver"
327- )
328- site_packages_path = os .path .dirname (spec .origin )
329- clidriver_bin_path = os .path .join (site_packages_path , "clidriver" , "bin" )
330- if os .path .exists (clidriver_bin_path ):
331- os .add_dll_directory (clidriver_bin_path )
332- logger .info (f"Added default CLI driver location to DLL search path: '{ clidriver_bin_path } '" )
333- else :
334- logger .info (f"Default CLI driver location folder not found: '{ clidriver_bin_path } '" )
324+ if not self .ibmdb_driver_already_added_to_path :
325+ spec = importlib .util .find_spec (db_api_module_name )
326+ if spec is not None :
327+ logger .info (
328+ f"Importing DB module '{ db_api_module_name } ' on Windows requires configuring the DLL directory for CLI driver"
329+ )
330+ site_packages_path = os .path .dirname (spec .origin )
331+ clidriver_bin_path = os .path .join (site_packages_path , "clidriver" , "bin" )
332+ if os .path .exists (clidriver_bin_path ):
333+ os .add_dll_directory (clidriver_bin_path )
334+ self .ibmdb_driver_already_added_to_path = True
335+ logger .info (f"Added default CLI driver location to DLL search path: '{ clidriver_bin_path } '" )
336+ else :
337+ logger .info (f"Default CLI driver location folder not found: '{ clidriver_bin_path } '" )
335338
336339 db_api_2 = importlib .import_module (db_api_module_name )
337340
0 commit comments