DataService.GetConnectionString | System.Data.SqlClient.SqlException (0x80131904): MSDTC on server 'SERVER' is unavailable

0

I have written some insert queries those works fine when i try to use transactions i am getting the above exception. I tried to resolve using this link "MSDTC on server 'server is unavailable" but still not working. can some one help me out to reslove this.

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;
}
c#
sqltransaction
asked on Stack Overflow Apr 8, 2019 by Saif AK

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0