I have a simple application that uses Linq-to-SQL to retrieve and update data.
On my DataContext
I have a procedure called GET_DATA
that reads data from a non-SQL Server data source using a linked server. I use the data read to update a few tables on SQL Server.
The process of updating the data on SQL Server is done (summarizing) like this:
var db = new MyDBDataContext()
db.ExecuteCommand("Update table1 set field={0} where field={1}", value1, value2);
It works perfectly fine.
Now, the problem: a new requirement came to update 2 tables instead of one so I decided to add some transaction control:
using (var db = new MyDBDataContext())
using (var tran = new TransactionScope())
{
try
{
db.ExecuteCommand("Update table1 set field={0} where field={1}", value1, value2);
db.ExecuteCommand("Update table3 set field={0} where field={1}", value1, value2);
tran.Complete();
}
catch (Exception e)
{
tran.Dispose();
}
}
Once again it works fine, but after I update the data (regardless if the process fails or succeeds), if I try to run the search procedure, I get this error:
The operation could not be performed because OLE DB provider \"OraOLEDB.Oracle\" for linked server \"LINKED_SERVER_NAME\" was unable to begin a distributed transaction."}
The only way I can make it work again is if I right click on the ASP.Net development Server and close it. It seems that it is keeping something open, but I checked the dm_tran_session_transactions
DMV and I don't see any transactions open (I can see it if I debug into the method, but once the method is completed, no transaction is open)
FYI: the dbcontext
objects are different form the select to the update and I also tried to add db.SubmitChanges()
but it didn't work either.
Any advise would be helpful thanks
EDIT: The search procedure does not have transaction control inside it and it is called by a simple LINQ Statment:
var result = (from r in context.GET_DATA(parameter)
select new Object{
.....
}
);
return result.ToList();