Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:27:18+00:00 2026-06-04T06:27:18+00:00

I want to have a parent object delete itself and it’s child object in

  • 0

I want to have a parent object delete itself and it’s child object in a single transactionscope. I also want to check in both cases if the object to delete exists, and if the user has rights to the object. Consider the following code:

I get the MSDTC on server is unavailable exception. Is there anyway to pass the connection through my service methods?

Please see the example below:

// classes Flight, FlightService, FlightDao
// classes Pilot, PilotService, PilotDao

// FlightService
public void deleteFlight(Flight flight) {
    FlightDao flightDao = new FlightDao();
    Flight existingFlight = flightDao.findById(flight.Id);
    if (existingFlight != null) {
        using (TransactionScope scope = new TransactionScope()) {
            try {
                PilotService.Instance.deletePilot(flight.Pilot);
                flightDao.delete(flight);
            } catch (Exception e) {
                log.Error(e.Message, e);
                throw new ServiceException(e.Message, e);
            }
            scope.Complete();   
        }
    }       
}

// PilotService
public void deleteFlight(Pilot pilot) {
    PilotDao pilotDao = new PilotDao();
    Pilot existingPilot = pilotDao.findById(pilot.Id); // THIS LINE RIGHT HERE THROWS EXCEPTION
    if (existingPilot != null) { 
        using (TransactionScope scope = new TransactionScope()) {
            try {               
                pilotDao.delete(pilot);
            } catch (Exception e) {
                log.Error(e.Message, e);
                throw new ServiceException(e.Message, e);
            }
            scope.Complete();   
        }
    }       
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:27:20+00:00Added an answer on June 4, 2026 at 6:27 am

    The problem here was that I was trying to use the same SqlDataReader multiple times within the same loop. This defintiely does not work inside a transaction.

    Example:

    SqlCommand command = new SqlCommand(...);
    SqlDataReader reader = command.ExecuteReader();
    if (reader.read()) {
      return buildMyObject(reader);
    }
    
    private MyObject buildMyObject(SqlDataReader reader) {
      MyObject o1 = new MyObject();
      // set fields on my object from reader
    
      // broken! i was attempting create a new sql connection here and attempt to use a reader
      // but the reader is already in use.
      return o1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables without any cascade deleting. I want to delete parent object
Supposing I have two entities a parent object and a child. I want the
I have two tables Loan(Parent Table) and Receipt(Child table)what i want to do is
I have django model which consist of parent child relationship filed I want to
I have several child windows, all with the same parent. I want to cascade/tile
I have a parent to child relationship. My problem is, when I access the
i would like to have bidirectional navigation methods in classes between child object and
Let's say I have a Parent object like this (in pseudo code) public Parent()
I have a parent object of type Parent and it currently has a null
I have treeview control with one level of parent and child nodes, each node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.