471,889 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,889 software developers and data experts.

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

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
2 17645
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
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.

Similar topics

4 posts views Thread by Julia | last post: by
1 post views Thread by =?Utf-8?B?RWFnbGVSZWRASGlnaEZseWluZ0JpcmRzLmNvbQ== | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.