entity-frameworksql-server-2014sqlfilestream

GET_FILESTREAM_TRANSACTION_CONTEXT() is null


I'm having issues getting a file from a FILESTREAM varbinary(max) column.

I added it to a table using this:

ALTER TABLE [dbo].News ADD RowGuidColId 
     UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE DEFAULT (NewId())
GO

ALTER TABLE News ADD NewsPngFile varbinary(max) FILESTREAM NULL
GO

I insert the picture using entity framework. But when I try to query, the GET_FILESTREAM_TRANSACTION_CONTEXT() returns NULL. What might be wrong?

enter image description here


Solution

  • Have you already committed the transaction? To use this you need to explicity open a transaction, obtain the transaction context with the call to GET_FILESTREAM_TRANSACTION_CONTEXT() and then commit. GET_FILESTREAM_TRANSACTION_CONTEXT() will return NULL if the transaction has not been started, or has been canceled or committed.

    There's a bit of documentation with an example available here:

    GET_FILESTREAM_TRANSACTION_CONTEXT (Transact-SQL)