Periodically I get an error when working with files from the database. Entity Framework , on the base Filestream which is used to store files. I can not understand why this error takes off:

FILESTREAM close operation using the same transaction. The transaction will be rolled back.

Maybe someone saw a similar error and how did you fight it ?!


Usually flies to commit or SaveChanges


In the SQL profiler, I found the following entries: First error:

  2013-06-26 09:44:00.74 spid10s Error: 3910, Severity: 16, State: 1. 2013-06-26 09:44:00.74 spid10s Transaction context in use by another session 

It belongs to the master database.
The remaining errors in my database. After this, two errors begin to fall: This operation conflicts with another pending operation on this transaction. The operation failed. This operation conflicts with another pending operation on this transaction. The operation failed.

And at the end another mistake:

 The transaction has been stopped because it conflicted with the execution of a FILESTREAM close operation using the same transaction. The transaction will be rolled back. 

Most recently, I discovered that an error only occurs when the next request is not executed, while the profiler for this request is in the column DataBaseName='master' . Here is the query:

 UPDATE [Docs].[dbo].[Files] SET [file_body] = [file_body].NewFilestreamValue () WHERE [file_body].RowGuid () = @hint OPTION (MAXDOP 1) 

I didn’t find what the NewFilestreamValue() function NewFilestreamValue() and where you can read about it, maybe it will give a clue

  • First, a transaction error always usually crashes to commit. but in fact: you do not accidentally open the same file several times without closing it? - Max Zhukov
  • Creating a filestream is placed in a using block when exiting a block, it must close! And the feeling that he does not have time to do it! Because if the filestream is taken out of the using block and the filestream is not closed, the same error takes off. - romandrovich

2 answers 2

I understand everything. Faced with a similar problem. This is a bug of microsoft. At Stream , even when included in the using block, there are problems with Dispose . Must be removed by hand. Try it.

Here, for example, is the description of the problem: Understanding Streams and their lifetime (Flush, Dispose, Close) .

    As far as I remember, this is a .NET error and it is treated with a patch KB2255379

    • This patch is for the Microsoft .NET Framework 2.0, and I use the .NET Framework 4.0, so it looks like it won't work for me! - romandrovich