I am coding a MVC 5 internet application and am using HangFire
for recurring jobs. I am deploying my internet application to Azure
and am using SQL Server
storage.
Here is my Startup.Auth code:
app.UseHangfire(config =>
{
config.UseAuthorizationFilters(new AuthorizationFilter
{
Roles = "Admin" // allow only specified roles
});
config.UseSqlServerStorage("CanFindLocationDatabaseContext");
config.UseServer();
});
HangFireService hangFireService = new HangFireService();
RecurringJob.AddOrUpdate(ApplicationConstants.accountUpdateSubscriptionPlanDetailForEachAccountCallerFunctionTaskId, () => hangFireService.UpdateSubscriptionPlanDetailForEachAccountCallerFunction(), Cron.Hourly);
The UpdateSubscriptionPlanDetailForEachAccountCallerFunction
function uses entity framework to look through some model objects and update some values every hour.
I am using ELMAH
for logging exceptions and at the end of the day, when looking at the ELMAH
logs, I am getting many of the following errors:
Error occurred during execution of ‘Worker #(number)’ component.
Execution will be retried (attempt 1 of 10) in 00:00:00 seconds.
Here is more information about the error:
System.Data.SqlClient.SqlException (0x80131904): A transport-level
error has occurred when receiving results from the server. (provider:
TCP Provider, error: 0 - The semaphore timeout period has expired.)
—> System.ComponentModel.Win32Exception (0x80004005): The semaphore timeout period has expired at
System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject
stateObj, UInt32 error) at
System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
at System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at
System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj, Boolean& dataReady) at
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at
System.Data.SqlClient.SqlDataReader.get_MetaData() at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,
RunBehavior runBehavior, String resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean
async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader
ds) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at Dapper.SqlMapper.<QueryImpl>d__11
1.MoveNext() at
System.Collections.Generic.List1..ctor(IEnumerable
1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable
1
commandTimeout, Nullable`1 commandType) at
Hangfire.SqlServer.SqlServerJobQueue.Dequeue(String queues,
CancellationToken cancellationToken) at
Hangfire.SqlServer.SqlServerConnection.FetchNextJob(String queues,
CancellationToken cancellationToken) at
Hangfire.Server.Worker.Execute(CancellationToken cancellationToken)
at
Hangfire.Server.AutomaticRetryServerComponentWrapper.ExecuteWithAutomaticRetry(CancellationToken
cancellationToken)
ClientConnectionId:c1547381-0dce-47b9-afe6-02aed3b53f6d Error
Number:121,State:0,Class:20
How can I prevent this error from happening?
Thanks in advance.