我写了一些插入查询,当我尝试使用事务时,这些查询工作正常,但出现上述异常。我尝试使用此链接“ MSDTC on server 'server is unavailable”来解决,但仍然无法正常工作。有人可以帮我解决这个问题。
try
{
using (TransactionScope scope = new TransactionScope())
{
dLib = new DataLibrary("VillageMate", true);
dtInsertData = dLib.GetDataTable("SELECT * FROM VillageMate_ESS where LogID=(select max(LogID) from [VillageMate_ESS])");//Select the last inserted row from table
if (dtInsertData.Rows.Count > 0)
{
dLib = new DataLibrary("ESS", true);
sqlQUERY = "INSERT INTO [MSTR_Employee] (FirstName, NationalID, EmployeeCode,CreatedDateTime,RecordStatus) VALUES ('" + dtInsertData.Rows[0]["Name"].ToString() + " ' , '" + dtInsertData.Rows[0]["IDNumber"].ToString() + "' , '" + dtInsertData.Rows[0]["RFID"].ToString() + "' , '" + DateTime.Now.ToString() + "' , '" + true + "')";
sqlQUERY += "INSERT INTO [MSTR_Employee_Optional] (TNAEnrollID, CreatedDateTime,RecordStatus) VALUES ('" + dtInsertData.Rows[0]["RFID"].ToString() + "' , '" + DateTime.Now.ToString() + "' , '" + true + "')";
sqlQUERY += "INSERT INTO [ACS_Card] (CardNumber, StartDate,EndDate, GUIDCard, CreatedDateTime,RecordStatus) VALUES ('" + dtInsertData.Rows[0]["IDNumber"].ToString() + " ' , '" + dtInsertData.Rows[0]["ValidFromDate"].ToString() + "' , '" + dtInsertData.Rows[0]["ValidToDate"].ToString() + "' ,'" + dtInsertData.Rows[0]["RFID"].ToString() + "', '" + DateTime.Now.ToString() + "' , '" + true + "')";
sqlQUERY += "INSERT INTO [ACS_CardOption] (IsVisitorCard,IsGuardCard, TraceAccess, CreatedDateTime,RecordStatus) VALUES ('" + true +
" ' , '" + false + "' , '" + false + "' , '" + DateTime.Now.ToString() + "' , '" + true + "')";
sqlQUERY += "INSERT INTO [ACS_CardStatus] (CardStatus, CreatedDateTime,RecordStatus) VALUES ('" + 5 +
" ' , '" + DateTime.Now.ToString() + "' , '" + true + "')";
sqlQUERY += "INSERT INTO [ACS_ActivityTransaction] (ActivityStatus, ActivityFailCount,ActivitySource, CreatedDateTime,RecordStatus) VALUES ('" + true +" ' , '" + 0 + "' , '" + 0 + "' , '" + DateTime.Now.ToString() + "' , '" + true + "')";
int status = dLib.ExecuteNonQuery(sqlQUERY);
}
scope.Complete();
scope.Dispose();
}
}
catch (Exception ee)
{
WriteLogs.WriteErrorLogs(-1, 0, GetType().FullName + "." + MethodBase.GetCurrentMethod().Name, ee.ToString());
return null;
}
finally
{
dLib = null;
dtInsertData = null;
}
return dtInsertData;
}