If you enlist a connection in a transaction and then close the connection the connection is kept open under the covers until the transaction is committed. If the connection could be closed there would be no way to tell Sql to commit the transaction and you'd get an orphaned transaction for that spid in sql (or it would abort). In the original code that you have you really do have 100 connections open at once and so on the 101st attempt to get a connection you timeout because all connections in the pool are busy (waiting for the transaction to complete).
If you really need to make all 4000 workflows consistent you'll need to share the same connection for each of the Unload calls. The SqlWorkflowPersistenceService can't do this in V1. If you write your own persistence service you can get this to work. The logic would be something like: open a transaction scope, create a connection, stick in threadlocal storage, create and call Unload on all of your workflows. In your WorkflowPersistenceService's implementation of SaveWorkflowState you'd look for the connection in threadlocal storage and use that connection. Just before you complete your transaction scope you'd close the shared connection.
Thanks, Joel West MSFTE - SDE in WF runtime and hosting
This posting is provided "AS IS" with no warranties, and confers no rights
|