Thanks for reaching out.
Your local run succeeds because it uses credentials and local network context. In Azure, a 500 indicates the Function can’t authenticate or reach SQL/Key Vault. Fix by enabling the Function’s Managed Identity, granting it AAD access to SQL (CREATE USER FROM EXTERNAL PROVIDER + roles), using Authentication=ActiveDirectoryMsi in the connection string, and ensuring Key Vault RBAC + (if applicable) VNet/Private DNS for private endpoints. Validate with Application Insights and Diagnose & Solve Problems. Docs & refs: Functions → SQL with Managed Identity • PyODBC MSI string • Python Functions MSI to SQL (ODBC 17.8) • Key Vault RBAC & identities • KV reference identity behavior • SQL firewall & Allow Azure services • Functions + VNet + Private Endpoints tutorial • App Insights / 500 troubleshooting.
Let us know if the issue persists after following these steps. I’ll be happy to assist further if needed. If the issue has been resolved, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.