Azure SQL Trigger Function fails with exception: Invalid object name 'az_func.Leases_xxx_xxx' after function redeployment.
I have an SQL Trigger Azure Function that is deployed to an Azure Function App as a container. The function image is stored in Azure Container Registry (ACR). All RBAC permissions (to pull from ACR, access the database, etc.) are correctly configured.
When I first start the function, it creates the table [az_func].[GlobalState] in the target database, as well as a lease table such as [az_func].[Leases_{FuncHash1}_{TableHash1}]. Everything works as expected at this stage.
The problem appears when I reinstall the function into the Function App. Essentially, I just swap the image tag in my ACR settings in the Function App Deployment Center and restart the Function App.
After this redeployment, I see an odd situation:
The function container starts up.
A new lease table is created, e.g. [az_func].[Leases_{FuncHash2}_{TableHash1}].
However, the Function App logs are filled with errors like:
[Error] Failed to check for changes in table 'Data.Trigger' (my CDC-enabled table)
due to exception: Microsoft.Data.SqlClient.SqlException.
Exception message: Invalid object name 'az_func.Leases_{FuncHash1}_{TableHash1}'.
So, instead of using the new lease table, the function continues to look for the old one from the previous deployment.
I have tried:
Rebuilding the image
Deleting the repository in ACR
Manually replacing the image tag with a specific version or using the generic latest
None of these helped. The function always throws the same exception:
Microsoft.Data.SqlClient.SqlException.
Exception message: Invalid object name 'az_func.Leases_{FuncHash1}_{TableHash1}'.
The function detects changes in the CDC-enabled table but fails to process them, since it only looks for the old lease table and does not properly switch to the new one.
Any idea why this happens? I couldn’t find anything relevant in the documentation. I have an SQL Trigger Azure Function that is deployed to an Azure Function App as a container.
The function image is stored in Azure Container Registry (ACR). All RBAC permissions (to pull from ACR, access the database, etc.) are correctly configured.
When I first start the function, it creates the table [az_func].[GlobalState] in the target database, as well as a lease table such as [az_func].[Leases_{FuncHash1}_{TableHash1}]. Everything works as expected at this stage.
The problem appears when I reinstall the function into the Function App. Essentially, I just swap the image tag in my ACR settings in the Function App Deployment Center and restart the Function App.
After this redeployment, I see an odd situation:
The function container starts up.
A new lease table is created, e.g. [az_func].[Leases_{FuncHash2}_{TableHash1}].
However, the Function App logs are filled with errors like:
[Error] Failed
So, instead of using the new lease table, the function continues to look for the old one from the previous deployment.
I have tried:
Rebuilding the image
Deleting the repository in ACR
Manually replacing the image tag with a specific version or using the generic latest
None of these helped. The function always throws the same exception:
Microsoft.Data.SqlClient.SqlException.
The function detects changes in the CDC-enabled table but fails to process them, since it only looks for the old lease table and does not properly switch to the new one.
Any idea why this happens? I couldn’t find anything relevant in the documentation.