By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.RequestErrorTableAdap ter requestErrorTA =
new DocumentDataSetTableAdapters.RequestErrorTableAdap ter();

TableAdapterHelper.SetTransaction(requestTA,
trans);

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

if (DateTime.Now >
requestRow.RequestDate.Add(Config.Instance.Handsha keTimeoutPeriod.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();
}
}
}

Mar 20 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Martin Z" <ma***********@gmail.comwrote in message
news:11*********************@n76g2000hsh.googlegro ups.com...
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.RequestErrorTableAdap ter requestErrorTA =
new DocumentDataSetTableAdapters.RequestErrorTableAdap ter();

TableAdapterHelper.SetTransaction(requestTA,
trans);

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

if (DateTime.Now >
requestRow.RequestDate.Add(Config.Instance.Handsha keTimeoutPeriod.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();
}
}
}

Mar 20 '07 #2

P: n/a
On Mar 19, 10:51 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

"Martin Z" <martin.zar...@gmail.comwrote in message

news:11*********************@n76g2000hsh.googlegro ups.com...
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.RequestErrorTableAdap ter requestErrorTA =
new DocumentDataSetTableAdapters.RequestErrorTableAdap ter();
TableAdapterHelper.SetTransaction(requestTA,
trans);
TableAdapterHelper.SetTransaction(requestErrorTA, trans);
TableAdapterHelper.SetTransaction(documentTA,
trans);
if (DateTime.Now >
requestRow.RequestDate.Add(Config.Instance.Handsha keTimeoutPeriod.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.

Mar 21 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.