I'm using TransactionScope object and it is giving me problems. The situation is like this.
I've 2 tables in sql server express, say student and courses and other one studentcourse for courses a student has opted for.
An aspx page displays list of users in listbox, when user chooses student, it fetches courses he has opted for and in the checkedlistbox (for courses) these courses are checked. Now when uses makes any changes to courses and clicks update button, i've
two functions at backend first one removes the courses which were previously selected but now not selected in postback, next it inserts courses which was not selected first but now are in this postback.
I use following code:
protected void Update(object sender, EventArgs e)
{
/*
get selections, existing courses etc.
*/
using(TransactionScope tscope=new TransactionScope())
{
try
{
RemoveCourses(/*Student*/ s, /*IList*/ oldCourses, /*IList*/ newCourses);
AddCourses(/*Student*/ s, /*IList*/ oldCourses, /*IList*/ newCourses);
tscope.Complete();
}
catch(Exception ex)
{
lblMessage.Text=ex.Message;
}
}
}
If any exception occurs during update and page is reload or I go to any other page where some data is fetched from sql server I get the exception:
Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction
Please help!