If a managed database has connections restricted to trusted sources, it is not possible to connect to it from serverless functions deployed to namespaces (outside the App Platform).
Consider adding an ability to specify a function, package, or namespace in the list of trusted sources of a database.