469,613 Members | 2,226 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Question about keeping transaction synchronized by usen the OleDbTransaction

Hello!

Below I have three methods it's SavePost, SavePostSetUpTableFlg and
SavePostBlowStepFlg.
I want to use transaction to keep the data synchronized. All or nothing must
be executed.

When I created the OleDbConnection and the OleDbAdapter I used the toolbox
and the wizard.
This method SavePost is just calling SavePostSetUpTableFlg and
SavePostBlowStepFlg,
Both methods SavePostSetUpTableFlg and SavePostBlowStepFlg is doing several
insert into two different tables.

Now to my question in method SavePost I have tried to implement transaction
handling in the way that I think
it should be done but I get runtime error when this statement is executing
mspLayoutAdapter.Fill( dSMspLayout ) in method SavePostBlowStepFlg
So I have a serious problem but I 'm unsure what should be done to solve it.
The run time error give a long error message but here is the first part of
it.
"System.InvalidOperationException: Execute requires the command to have a
transaction object when the connection assigned
to the command is in a pending local transaction. The Transaction property
of the command has not been initialized"

In SavePost I have this row "OleDbTransaction trx =
UTCAS.MeltPracStorage.instance.utcasMspDbConnectio n.BeginTransaction();"
this just get the OleDbTransaction from a class library that handle all
adapters and connections.
public bool SavePost(IDialogPostData post)
{
UTCAS.MeltPracStorage.instance.utcasMspDbConnectio n.Open();
OleDbTransaction trx =
UTCAS.MeltPracStorage.instance.utcasMspDbConnectio n.BeginTransaction();
try
{
SavePostSetUpTableFlg(post);
SavePostBlowStepFlg(post);
trx.Commit();
}
catch (Exception e)
{
trx.Rollback();
}
return false;
}

private void SavePostSetUpTableFlg(IDialogPostData post)
{
DataSet dSMspLayout = new DataSet();
OleDbDataAdapter mspLayoutAdapter =
MeltPracStorage.instance.mspLayoutAdapter;
MeltPracDataProcLayout mpd = post as
MeltPracDataProcLayout;

mspLayoutAdapter.SelectCommand.CommandText = "select * " +

"from MSP_LAYOUT t1 " +

"where t1.MSP_NAME = '" + mpd.PostName + "' and " +

"t1.STEELGRADE = '" + m_cboSteelGrades.SelectedItem.ToString() + "' and "
+

"t1.SAVE_TIME = " +

"(select max(SAVE_TIME) " +

"from MSP_LAYOUT " +

"where MSP_NAME = t1.MSP_NAME)";
mspLayoutAdapter.Fill( dSMspLayout );

if ( dSMspLayout.Tables[0].Rows.Count != 0 )
dSMspLayout.Tables[0].Rows[0]["ACTIVE"] = 0;

DataRow newRow = dSMspLayout.Tables[0].NewRow();
newRow["MSP_NAME"] = mpd.PostName;
newRow["ACTIVE"] = 1;
newRow["SAVE_TIME"] = mpd.SaveTime;
newRow["STEELGRADE"] = m_cboSteelGrades.SelectedItem.ToString();
int index = 0;
foreach( MeltPracDataProcLayout.SetUpTable sut in
mpd.getSetUpTableArrList() )
newRow[ Param[ index++ ] ] = sut.ParamPost;
dSMspLayout.Tables[0].Rows.Add( newRow );
mspLayoutAdapter.Update( dSMspLayout );
}

private void SavePostBlowStepFlg(IDialogPostData post)
{
DataSet dSMspLayout = new DataSet();
MeltPracDataProcLayout mpd = post as
MeltPracDataProcLayout;
OleDbDataAdapter mspBstepOrderAdapter =
MeltPracStorage.instance.mspBstepOrderAdapter;

mspBstepOrderAdapter.SelectCommand.CommandText = "select * " +
"from MSP_BSTEP_ORDER t1
" +
"where t1.MSP_NAME = '"
+ mpd.PostName + "' and " +
"t1.STEELGRADE = '"
+ m_cboSteelGrades.SelectedItem.ToString() + "' and " +
"t1.SAVE_TIME = " +
"(select max(SAVE_TIME)
" +
"from MSP_BSTEP_ORDER "
+
"where MSP_NAME =
t1.MSP_NAME)";
mspBstepOrderAdapter.Fill( dSMspLayout );

foreach( MeltPracDataProcLayout.BlowStep bs in mpd.getBlowStepArrList() )
{
DataRow nRow = dSMspLayout.Tables[0].NewRow(); // create a new
DataRow
nRow["ORDER_MSP"] = bs.Order;
nRow["MSP_NAME"] = mpd.PostName; // set from Base class
nRow["SAVE_TIME"] = mpd.SaveTime; // set from Base class
nRow["STEELGRADE"]= m_cboSteelGrades.SelectedItem.ToString();
nRow["COND_VAL"] = bs.Value;
dSMspLayout.Tables[0].Rows.Add( nRow ); // add the new row to the
dataset
}
mspBstepOrderAdapter.Update( dSMspLayout ); // insert into db
}

//Tony
Jun 16 '06 #1
0 1323

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Eyal Cohen | last post: by
2 posts views Thread by Banski | last post: by
4 posts views Thread by John | last post: by
4 posts views Thread by Sin Jeong-hun | last post: by
6 posts views Thread by fniles | last post: by
3 posts views Thread by Gary W. Smith | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.