System.Data.SqlClient.SqlException 3988


Exception Type: System.Data.SqlClient.SqlException
Number: 3988
Message: New transaction is not allowed because there are other threads running in the session


If you have ever seen this type of exception when talking to RTM SQL Server 2005 (but never saw it with the Beta version of the server), it's likely that you have an open data reader associated with the connection when starting a new transaction.


The change (from Beta to RTM) is by-design. To avoid non-determinate transaction state, the request of a transaction should be the only request when you execute a transaction. In other words, you have to close the reader associated with the connection before starting a new transaction.

Comments (3)

  1. Charles says:

    I have seem this kind of information many times, it still doesn’t make sense to me even you said it was by design. If you think about a scenario like:

    open cursor

    loop {

      fetch cursor

      begin tran

      update table

      commit tran

    }

    close cursor

    Above is the typical logic in many applications, I am using cursor here to make it easier explain, which it could be called Reader or rowset whatever. In this case I need open one connection and keep the rowset active while a new transaction begin and end.

    Looked Cihan’s blog as well, http://blogs.msdn.com/cbiyikoglu/archive/2006/11/21/mars-transactions-and-sql-error-3997-3988-or-3983.aspx

    his two solutions are not realistic at all in the real life.

    I had the similiar problems before, when I did work around I found if setting MARS on and using server side cursor property when creating rowset, the errors would disappear. I ever tried to talk to different people from MS support, they could not give me a definate answer wether it was a right solution or not. Recently I changed around my application but the properties keep unchanged, the errors come back again.

    Can you advise if I want to keep the rowset open while I need a new transaction, what is the best way to do it?

    Thanks

  2. sonia says:

    thanks!

    you have helped me to find the problem to System.Data.SqlClient.SqlException 3988: "i had an opened sqldatareader in the same session"

  3. K.SURESH says:

    There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.

    HOW TO CLEAR THE ERROR

Skip to main content