Hello,
I have deployed my application on 3 tier environment: front-end, back-end, and database server, my problem between the back-end and the database server is it does not roll back all changes (e.g: _requestRepository does not roll back when _fileRepository failed) although I am using unitOfWorkManager:
var options = new UnitOfWorkOptions();
options.AsyncFlowOption = System.Transactions.TransactionScopeAsyncFlowOption.Enabled;
using (var unitOfWork = _unitOfWorkManager.Begin(options))
{
var reqId = await _requestRepository.InsertAndGetIdAsync(req);
foreach (NewFileInput fileInput in moiReq.Files)
{
var f = new UploadedFile
{
File = new File
{
ContentBase64 = fileInput.ContentBase64
},
Type = (int)FileType.AtCreation,
Desc = fileInput.Desc,
FileName = fileInput.FileName,
MimeType = fileInput.MimeType,
RequestId = req.Id,
TransactionId = req.Transactions[0].Id
};
await _fileRepository.InsertAsync(f);
}
unitOfWork.Complete();
Logger.InfoFormat("Request Created Successfully, ReqId:{0}", reqId);
.....
also I tried with sync and did not work, I appreciate your support to figure out where the problem?
Note: DTC is configured and working fine between the two servers :shock: . Also Note: it works and rolled back successfully if the back-end and database on same machine :( .
Thanks, Khaled
4 Answer(s)
-
0
Hi,
Is this code in an app service method ? Also, have you tried to start UoW like this
using (var unitOfWork = _unitOfWorkManager.Begin())
Thanks.
-
0
Hi, Thanks for replying. Is this code in an app service method ? YES. Also, have you tried to start UoW like this? YES. this is my connection string: <add connectionString="Data Source=IP Adress;Initial Catalog=DB;User ID=sa;Password=P@ssw0rd;Pooling=false;Enlist=false;" name="Default" providerName="System.Data.SqlClient" />
-
0
Oh!
Removed Enlist=false; from connection string solved the problem :mrgreen:
Thanks.
-
0
Great :),
Thanks for sharing.