none
TransactionScope is creating a problem. RRS feed

  • Question

  • hi i am facing an exception while using TransactionScope. BUT when I try to use 
    
    without TransactionScope then data is inserted into the db easily. 
    
     public void SaveIntoDB(Controller controller) 
        {
          
          using (TransactionScope tr = new TransactionScope())
          {
    
            try
            {
              LINQ.tbl_Company comp = new LINQ.tbl_Company
              {
                comp_ID = controller.Company.Company_ID,
                comp_Name = controller.Company.Company_Name
              };
              dc_obj.tbl_Companies.InsertOnSubmit(comp);
    
              LINQ.Department dept = new LINQ.Department
              {
                dept_ID = controller.Department.Dept_ID,
                dept_Name = controller.Department.Dept_Name,
                comp_ID = comp.comp_ID
              };
              dc_obj.Departments.InsertOnSubmit(dept);
    
              LINQ.employee emp = new LINQ.employee
              {
                emp_ID = controller.Employee.Emp_Code,
                emp_Name = controller.Employee.Emp_Name,
                salary = controller.Employee.Emp_Salary,
                dept_ID = dept.dept_ID,
                comp_ID = comp.comp_ID
              };
    
              dc_obj.employees.InsertOnSubmit(emp);
    
              dc_obj.SubmitChanges();
              tr.Complete();
            }
            catch (Exception ex)
            {
    
              Transaction.Current.Rollback(ex);
              throw ex;
            }          
          }
        
        }
    

    Exception is this:

     System.Web.Services.Protocols.SoapException was unhandled
      Message="System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. ---> System.Runtime.InteropServices.COMException (0x8004D01B): The Transaction Manager is not available. (Exception from HRESULT: 0x8004D01B)\n   at System.Transactions.Oletx.IDtcProxyShimFactory.ConnectToProxy(String nodeName, Guid resourceManagerIdentifier, IntPtr managedIdentifier, Boolean& nodeNameMatches, UInt32& whereaboutsSize, CoTaskMemHandle& whereaboutsBuffer, IResourceManagerShim& resourceManagerShim)\n   at System.Transactions.Oletx.DtcTransactionManager.Initialize()\n   --- End of inner exception stack trace ---\n   at System.Transactions.Oletx.OletxTransactionManager.ProxyException(COMException comException)\n   at System.Transactions.Oletx.DtcTransactionManager.Initialize()\n   at System.Transactions.Oletx.DtcTransactionManager.get_ProxyShimFactory()\n   at System.Transactions.Oletx.OletxTransactionManager.CreateTransaction(TransactionOptions properties)\n   at System.Transactions.TransactionStatePromoted.EnterState(InternalTransaction tx)\n   --- End of inner exception stack trace ---\n   at CrackerJack_Impacts.Dal.DataAccess.SaveIntoDB(Controller controller) in d:\\October 2010\\13-October-2010\\CrackerJack_Impacts\\App_Code\\DAL\\DataAccess.cs:line 69\n   at CrackerJack_Impacts.businessLogic.Controller.SaveINTODB() in d:\\October 2010\\13-October-2010\\CrackerJack_Impacts\\App_Code\\businessLogic\\Controller.cs:line 51\n   at Service.Proceed_Request(Controller controller) in d:\\October 2010\\13-October-2010\\CrackerJack_Impacts\\App_Code\\Service.cs:line 28\n   --- End of inner exception stack trace ---"
      Source="System.Web.Services"
      Actor=""
      Lang=""
      Node=""
      Role=""
      StackTrace:
           at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
           at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
           at WindowsFormsApplication3.CrackerJackWebService.Service.Proceed_Request(Controller controller) in c:\documents and settings\ahmedm\my documents\visual studio 2008\projects\crackerjack_impacts\windowsformsapplication3\web references\crackerjackwebservice\reference.cs:line 110
           at WindowsFormsApplication3.Form1..ctor() in C:\Documents and Settings\Ahmedm\My Documents\Visual Studio 2008\Projects\CrackerJack_Impacts\WindowsFormsApplication3\Form1.cs:line 45
           at WindowsFormsApplication3.Program.Main() in C:\Documents and Settings\Ahmedm\My Documents\Visual Studio 2008\Projects\CrackerJack_Impacts\WindowsFormsApplication3\Program.cs:line 17
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

     


    maifs
    Wednesday, October 13, 2010 2:50 PM

Answers

  • It looks like your trying to use a transaction scope on the other side of a web service.  If so, I would say that is a bad design.  You might want to look up N-Tiered applications, but here is the basic idea.

    Layer - UI - Display and interact with webservice.

    Layer - Webservice - Really just an adapter

    Layer - Business Logic - Transaction Scopes go here, and data itegerity is handled.

    Layer - Data Access - Database

    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:58 AM
    Wednesday, October 13, 2010 2:58 PM
  • ...  Like I said before, you shouldn't be using transaction scopes outside of the Business Logic Layer.

    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:58 AM
    Wednesday, October 13, 2010 4:17 PM

All replies

  • It looks like your trying to use a transaction scope on the other side of a web service.  If so, I would say that is a bad design.  You might want to look up N-Tiered applications, but here is the basic idea.

    Layer - UI - Display and interact with webservice.

    Layer - Webservice - Really just an adapter

    Layer - Business Logic - Transaction Scopes go here, and data itegerity is handled.

    Layer - Data Access - Database

    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:58 AM
    Wednesday, October 13, 2010 2:58 PM
  • dear its a N-tiered apporoach. there are four layers of my application.
    maifs
    Wednesday, October 13, 2010 3:18 PM
  • ...  Like I said before, you shouldn't be using transaction scopes outside of the Business Logic Layer.

    • Marked as answer by Mehmood Ahmed Thursday, October 14, 2010 9:58 AM
    Wednesday, October 13, 2010 4:17 PM