I have this code to write an image into 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 suggested that it's timeout issue and I've tried to change the transaction timeout but it didn't work.
I've tried to use the same code on another server and it's working fine.
I'm not facing any problem with the database connection, but after writing on SqlFileStream
context after oTransaction.Complete()
line when the using
brackets closed it throws an TransactionAbortedException with this message:
"An uncommittable transaction was detected at the beginning of the batch. The transaction was rolled back. This was caused by an error that occurred during the processing of a FILESTREAM request in the context of this transaction."