"ExecuteReader request the command to have a transaction..." error occurring when the reader plainly

  • Thread starter Thread starter Martin Z
  • Start date Start date
M

Martin Z

I'm using the TableAdapterHelper to set the connection and transaction
properties on all the commands of all my typed table adapters.... I've
checked at the time of the error and all the commands have their
Transaction property set. But I still get this error when I call...

documentTA.Update(documentDS.Document[0]);

"ExecuteReader requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction.
The Transaction property of the command has not been initialized."

does the tableadapter update use additional derived commands or
something?

The whole loop below:

foreach (DocumentDataSet.RequestRow requestRow in documentDS.Request)
{
using(SqlConnection conn = new
SqlConnection(Config.Instance.DatabaseConnection))
{
conn.Open();
using (SqlTransaction trans =
conn.BeginTransaction())
{


DocumentDataSetTableAdapters.DocumentTableAdapter documentTA = new
DocumentDataSetTableAdapters.DocumentTableAdapter();

DocumentDataSetTableAdapters.RequestTableAdapter requestTA = new
DocumentDataSetTableAdapters.RequestTableAdapter();

DocumentDataSetTableAdapters.RequestErrorTableAdapter requestErrorTA =
new DocumentDataSetTableAdapters.RequestErrorTableAdapter();

TableAdapterHelper.SetTransaction(requestTA,
trans);

TableAdapterHelper.SetTransaction(requestErrorTA, trans);
TableAdapterHelper.SetTransaction(documentTA,
trans);

if (DateTime.Now >
requestRow.RequestDate.Add(Config.Instance.HandshakeTimeoutPeriod.TimeSpan))
{
requestRow.RequestStatusID =
(int)RequestStatus.Error;
CreateRequestErrorRow(documentDS,
requestRow, "CODE_FAILURE", "MSG_HANDSHAKETIME", requestErrorTA);
}


documentTA.FillByDocumentID(documentDS.Document,
requestRow.DocumentID);
if
(documentDS.Document[0].IsParentDocumentIDNull())
{
//is original registration
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ActionReq;
}
else
{
//is subdoc
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ActionReq;
documentTA.Update(documentDS.Document[0]);

//update parent

documentTA.FillByDocumentID(documentDS.Document,
documentDS.Document[0].ParentDocumentID);
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ReviewNotice;
}

documentTA.Update(documentDS.Document);
requestTA.Update(documentDS.Request);

requestErrorTA.Update(documentDS.RequestError);
trans.Commit();
}
}
}
 
Martin,

You will have to show the code behind the
TableAdapterHelper.SetTransaction method. Without that, we can't see how
you are working with the transaction.

Also, have you considered using the TransactionScope class in the
System.Transactions namespace?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Martin Z said:
I'm using the TableAdapterHelper to set the connection and transaction
properties on all the commands of all my typed table adapters.... I've
checked at the time of the error and all the commands have their
Transaction property set. But I still get this error when I call...

documentTA.Update(documentDS.Document[0]);

"ExecuteReader requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction.
The Transaction property of the command has not been initialized."

does the tableadapter update use additional derived commands or
something?

The whole loop below:

foreach (DocumentDataSet.RequestRow requestRow in documentDS.Request)
{
using(SqlConnection conn = new
SqlConnection(Config.Instance.DatabaseConnection))
{
conn.Open();
using (SqlTransaction trans =
conn.BeginTransaction())
{


DocumentDataSetTableAdapters.DocumentTableAdapter documentTA = new
DocumentDataSetTableAdapters.DocumentTableAdapter();

DocumentDataSetTableAdapters.RequestTableAdapter requestTA = new
DocumentDataSetTableAdapters.RequestTableAdapter();

DocumentDataSetTableAdapters.RequestErrorTableAdapter requestErrorTA =
new DocumentDataSetTableAdapters.RequestErrorTableAdapter();

TableAdapterHelper.SetTransaction(requestTA,
trans);

TableAdapterHelper.SetTransaction(requestErrorTA, trans);
TableAdapterHelper.SetTransaction(documentTA,
trans);

if (DateTime.Now >
requestRow.RequestDate.Add(Config.Instance.HandshakeTimeoutPeriod.TimeSpan))
{
requestRow.RequestStatusID =
(int)RequestStatus.Error;
CreateRequestErrorRow(documentDS,
requestRow, "CODE_FAILURE", "MSG_HANDSHAKETIME", requestErrorTA);
}


documentTA.FillByDocumentID(documentDS.Document,
requestRow.DocumentID);
if
(documentDS.Document[0].IsParentDocumentIDNull())
{
//is original registration
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ActionReq;
}
else
{
//is subdoc
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ActionReq;
documentTA.Update(documentDS.Document[0]);

//update parent

documentTA.FillByDocumentID(documentDS.Document,
documentDS.Document[0].ParentDocumentID);
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ReviewNotice;
}

documentTA.Update(documentDS.Document);
requestTA.Update(documentDS.Request);

requestErrorTA.Update(documentDS.RequestError);
trans.Commit();
}
}
}
 
Martin,

You will have to show the code behind the
TableAdapterHelper.SetTransaction method. Without that, we can't see how
you are working with the transaction.

Also, have you considered using the TransactionScope class in the
System.Transactions namespace?

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I'm using the TableAdapterHelper to set the connection and transaction
properties on all the commands of all my typed table adapters.... I've
checked at the time of the error and all the commands have their
Transaction property set. But I still get this error when I call...
documentTA.Update(documentDS.Document[0]);

"ExecuteReader requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction.
The Transaction property of the command has not been initialized."
does the tableadapter update use additional derived commands or
something?
The whole loop below:
foreach (DocumentDataSet.RequestRow requestRow in documentDS.Request)
{
using(SqlConnection conn = new
SqlConnection(Config.Instance.DatabaseConnection))
{
conn.Open();
using (SqlTransaction trans =
conn.BeginTransaction())
{
DocumentDataSetTableAdapters.DocumentTableAdapter documentTA = new
DocumentDataSetTableAdapters.DocumentTableAdapter();
DocumentDataSetTableAdapters.RequestTableAdapter requestTA = new
DocumentDataSetTableAdapters.RequestTableAdapter();
DocumentDataSetTableAdapters.RequestErrorTableAdapter requestErrorTA =
new DocumentDataSetTableAdapters.RequestErrorTableAdapter();

TableAdapterHelper.SetTransaction(requestErrorTA, trans);
TableAdapterHelper.SetTransaction(documentTA,
trans);
if (DateTime.Now >
requestRow.RequestDate.Add(Config.Instance.HandshakeTimeoutPeriod.TimeSpan)­)
{
requestRow.RequestStatusID =
(int)RequestStatus.Error;
CreateRequestErrorRow(documentDS,
requestRow, "CODE_FAILURE", "MSG_HANDSHAKETIME", requestErrorTA);
}
documentTA.FillByDocumentID(documentDS.Document,
requestRow.DocumentID);
if
(documentDS.Document[0].IsParentDocumentIDNull())
{
//is original registration
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ActionReq;
}
else
{
//is subdoc
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ActionReq;
documentTA.Update(documentDS.Document[0]);
//update parent
documentTA.FillByDocumentID(documentDS.Document,
documentDS.Document[0].ParentDocumentID);
documentDS.Document[0].DocumentStatusID =
(int)DocumentStatus.ReviewNotice;
}
documentTA.Update(documentDS.Document);
requestTA.Update(documentDS.Request);

requestErrorTA.Update(documentDS.RequestError);
trans.Commit();
}
}
}- Hide quoted text -

- Show quoted text -

Figured it out. The TableAdapterHelper sets all the commands
transactions... but the .Update() command doesn't use an existing
command, it dynamically builds one. This, of course, means that the
transaction is not set on that command. So I'm using manual SQL
statements instead of Update.

I should be using a transaction scope, but the server does not have
the distributed transaction coordinator enabled, and I can't figure
out how to get transaction scopes to work without one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top