Reputation: 8241
I am using Transactionscope with linqtosql. I have the following code:
public bool Save(int Id, List<Student> students, List<Subject> subjects)
{
var isDataSaved = false;
using (TransactionScope scope = new TransactionScope())
{
try
{
// Save the students
SaveStudents(students);
// Save the subjects
SaveSubjects(subjects);
scope.Complete();
isDataSaved = true;
}
catch (Exception ex)
{
throw ex;
}
return isDataSaved;
}
}
In both the methods I am using the two tables : Students, Subjects present in the same database. The datacontext object dependency is setup using the constructor as mentioned in the below class:
public class StudentsRepository:IStudentsRepository
{
public StudentsRepository()
{
_dataContext = new SchoollDetailsDataContext(connectionString);
}
}
The same datacontext object is used in both the methods SaveStudents and SaveSubjects.
I am getting an exception : MSDTC on server 'servername' is unavailable.
As per my initial analysis this kind of error will occur where a database operation will be in my local database and another will be in a remote database.
Can anyone help me to know is there anything I am missing here?
Upvotes: 2
Views: 1442
Reputation: 23
You need to turn the MSDTC service on.
Start-->Control Panel --> Administrative Tools --> services. Find the service Distributed Transaction Coordinator and start it. By default its startup property is set to Manual so its switched off.
Upvotes: 1