C
ChrisB
Hello All:
I am attempting to write data access code that is transactional and seem to
be running into some issues.
A simplified version of the logic I am using is as follows:
1. Create connection object.
2. Create transaction object that references connection object.
3. Create and populate datareader using transactional object (call A).
4. While(datareader.Read)
{
Perform some action using datareader . . .
Make another call to the database using value from current record loaded
into datareader (call B - repeated once for each object in datareader).
Additional code here . . .
}
5. Commit transaction.
The issue is occuring during step 4. When I make the call to the database
in the while loop, I would like the call to be covered under the existing
transaction, therefore I am using the transaction object created earlier.
From what I understand, however, only one datareader may be associated with
a given connection at a time.
My dilemma is as follows:
1. If the data reader is closed before making call B, I will lose the data
stored in the reader from call A.
2. If a new data reader is created for call B, call B will no longer be
associated with the same connection/transaction as call A.
Is there a way to have calls A and B within the same transaction?
Thanks for any input!
Chris
I am attempting to write data access code that is transactional and seem to
be running into some issues.
A simplified version of the logic I am using is as follows:
1. Create connection object.
2. Create transaction object that references connection object.
3. Create and populate datareader using transactional object (call A).
4. While(datareader.Read)
{
Perform some action using datareader . . .
Make another call to the database using value from current record loaded
into datareader (call B - repeated once for each object in datareader).
Additional code here . . .
}
5. Commit transaction.
The issue is occuring during step 4. When I make the call to the database
in the while loop, I would like the call to be covered under the existing
transaction, therefore I am using the transaction object created earlier.
From what I understand, however, only one datareader may be associated with
a given connection at a time.
My dilemma is as follows:
1. If the data reader is closed before making call B, I will lose the data
stored in the reader from call A.
2. If a new data reader is created for call B, call B will no longer be
associated with the same connection/transaction as call A.
Is there a way to have calls A and B within the same transaction?
Thanks for any input!
Chris