How to Load Data from Database into Custom Files (v2021)

Hi,
It seems this does NOT work with v2024. may I ask you suggest the above code for 2024?
thanks