Transaction exception canceled
I have this code to write an image to SqlFileStream
,
string strFileId;
using (var oTransaction = new TransactionScope()) {
var oSqlParameter = new SqlParameter[5];
oSqlParameter[0] = new SqlParameter("@FileName", imageName);
oSqlParameter[1] = new SqlParameter("@Description", "Description");
oSqlParameter[2] = new SqlParameter("@MimeType", mimeType);
oSqlParameter[3] = new SqlParameter("@Size", size);
oSqlParameter[4] = new SqlParameter("@FileObjectsId", SqlDbType.UniqueIdentifier, 100) { Direction = ParameterDirection.Output };
DataSet ds = DataAccess.ExecuteDataset(ConnString, CommandType.StoredProcedure, "SPInsImage", oSqlParameter);
strFileId = ds.Tables[0].Rows[0]["FileObjectsId"].ToString();
string strSqlPath = ds.Tables[0].Rows[0]["Column1"].ToString();
var bytArrContext = (byte[])ds.Tables[0].Rows[0]["Column2"];
var fileStream = new SqlFileStream(strSqlPath, bytArrContext, FileAccess.Write);
fileStream.Write(content, 0, content.Length);
fileStream.Close();
oTransaction.Complete();
}// throw an TransactionAbortedException
return strFileId;
Other blogs have suggested a timeout issue and I tried to change the transaction timeout but it didn't work.
I tried to use the same code on another server and it works fine.
I don't face any kind of database connection issue, but after writing to the SqlFileStream
context after the line oTransaction.Complete()
when the brackets using
are closed, it throws a TransactionAbortedException with this message:
"An invalid transaction was detected early in the batch. The transaction was canceled. This was caused by an error that occurred while processing a FILESTREAM request in the context of this transaction."
source to share
No one has answered this question yet
Check out similar questions: