I have a function app which is time triggered only once per day.
It connects to Azure SQL Server using Managed Service Identity (MSI).
I am creating SqlConnection object in the static constructor. I am setting AccessToken to the SqlConnection object using
new SqlConnection(this.ConnectionString)
{
// AzureServiceTokenProvider handles caching the token and refreshing it before it expires
AccessToken = new AzureServiceTokenProvider().GetAccessTokenAsync("https://database.windows.net/").Result
};
Every time I restart the Function App, it works fine. But from the next day (24 hours later) I get the error Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
It works intermittently (once in few days).
Exception Call Stack
System.Data.SqlClient.SqlException:
at Microsoft.SupplyChain.Dependency.AutofacInterceptionLogBehavior.Intercept (Microsoft.SupplyChain.Dependency, Version=1.22019.1206.1, Culture=neutral, PublicKeyToken=null)
at Castle.DynamicProxy.AbstractInvocation.Proceed (Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc)
at Castle.Proxies.IUoWProxy.ExecuteQuery (DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)
at DataIngestor.Foo+<Update>d__11.MoveNext (DataIngestor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at DataIngestor.Foo+<Run>d__5.MoveNext (DataIngestor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullIDataHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: D:\a\1\s\MasterData\PartNumberIngestion\DataHandler\Foo.csDataIngestor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 135)
Appreciate any help.
Thanks in advance.