Thread abort leaves zombie transactions and broken SqlConnection

前端 未结 2 591
萌比男神i
萌比男神i 2021-02-07 09:24

I feel like this behavior should not be happening. Here\'s the scenario:

  1. Start a long-running sql transaction.

  2. The thread that ran the sql comm

2条回答
  •  耶瑟儿~
    2021-02-07 10:24

    This is a bug in Microsoft's MARS implementation. Disabling MARS in your connection string will make the problem go away.

    If you require MARS, and are comfortable making your application dependent on another company's internal implementation, familiarize yourself with http://dotnet.sys-con.com/node/39040, break out .NET Reflector, and look at the connection and pool classes. You have to store a copy of the DbConnectionInternal property before the failure occurs. Later, use reflection to pass the reference to a deallocation method in the internal pooling class. This will stop your connection from lingering for 4:00 - 7:40 minutes.

    There are surely other ways to force the connection out of the pool and to be disposed. Short of a hotfix from Microsoft, though, reflection seems to be necessary. The public methods in the ADO.NET API don't seem to help.

提交回复
热议问题