SQL Server and TransactionScope (with MSDTC): Sporadically can't get connection

后端 未结 1 922
清酒与你
清酒与你 2021-01-23 04:57

I\'ve written some tests for .net code that invokes calls to my SQL Server. It appears that using System.Transactions is an excellent choice for rolling back any m

1条回答
  •  孤街浪徒
    2021-01-23 05:20

    I found the problem. One of the methods I was testing uses a SqlDataReader object. Apparently, the Close() method must be called before the SqlDataReader goes out of scope in order to release the connection, but in my case, I failed to do so.

    Simply adding mySqlDataReader.Close() to the end of the method under test fixed the problem. Also, the test method to test this particular method was data-driven with over 100 test cases, so that explains how I could have run out of connections.

    0 讨论(0)
提交回复
热议问题