"Thread was interrupted from a waiting state" at DbConnectionPool.CleanupCallback

Pedro Gonçalves 25 Reputation points
2023-09-22T16:36:55.1933333+00:00

Hi,

I'm getting this error, and I'm not able to fix it, or even understand from where it comes.

I'm also sure that all my SqlConnection are instanciated with Using (VB.NET), so the Dispose should be called for every one.

Does anyone have an idea about the cause?

This error seems to start after upgraded the app from .NET Framework from 4.6.2 to 4.8.1. But, I'm sure it's a coincidence...

Source: mscorlib; Message: Thread was interrupted from a waiting state.; Data:; StackTrace:    at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
   at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
   at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.TimerQueueTimer.CallCallback()
   at System.Threading.TimerQueueTimer.Fire()
   at System.Threading.TimerQueue.FireNextTimers();

Regards,

Pedro

Developer technologies | VB
Developer technologies | C#
{count} vote

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-09-28T08:30:21.6833333+00:00

    Hi @Pedro Gonçalves ,

    Try add Pooling=False in your connection string.

    With Pooling=False, each time you open a connection, it will create a new, separate connection to the database, and it won't be pooled for reuse. When you close the connection, it will be completely closed and won't be reused by other parts of your application.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.