Page 1 of 1
Master-Detail transaction problem
Posted: Thu 22 Jan 2009 12:27
by Sergey Schukin
There are two tables Master-Detail, do so:
1.begin transaction
Code: Select all
transaction = connection.BeginTransaction()
2. Add row to Master dataset
3. Add rows to Master dataset
4. apply to adapters
Code: Select all
adp1.Transaction=transaction
adp2.Transaction=transaction
5. Make update
Code: Select all
adp1.Update(myMasterRow)
adp2.Update(myDetailTable)
6. and at last
The application not responding on line 5.2
Table Detail (or rows in it) as I have understood appear blocked.
What is the trouble?
(Oracle 9.2, dotConnect for Oracle 5.0.16.0)
Posted: Thu 22 Jan 2009 13:39
by Shalex
Could you please try using this code:
Code: Select all
using (OracleConnection connection = new OracleConnection(@"Server=ora920;Port=1521;uid=xx;pwd=xxx;")) {
OracleDataTable deptTable = new OracleDataTable("select * from dept", connection);
OracleDataTable empTable = new OracleDataTable("select * from emp", connection);
deptTable.Open();
empTable.Open();
DataSet ds = new DataSet();
ds.Tables.Add(deptTable);
ds.Tables.Add(empTable);
DataRelation deptEmpRel = new DataRelation("dept_emp", deptTable.Columns["deptno"], empTable.Columns["deptno"]);
deptTable.ChildRelations.Add(deptEmpRel);
OracleTransaction transaction = connection.BeginTransaction();
try {
DataRow deptRow1 = deptTable.NewRow();
deptRow1["deptno"] = 12;
deptRow1["dname"] = "Support";
deptTable.Rows.Add(deptRow1);
deptTable.Update();
DataRow empRow1 = empTable.NewRow();
empRow1["empno"] = 7777;
empRow1["deptno"] = 12;
empRow1["ename"] = "Ronald";
empTable.Rows.Add(empRow1);
empTable.Update();
transaction.Commit();
}
catch (Exception ex) {
transaction.Rollback();
MessageBox.Show(ex.Message);
}
}
You can find the script that creates the Dept and Emp tables in this thread:
http://www.devart.com/forums/viewtopic.php?t=13955 .
Please give us a more detailed example of the issue you described in your previous post. What adapters are you using?
Posted: Thu 22 Jan 2009 14:10
by Sergey Schukin
I'm using standart dataset (FW3.5) created in MSDataSetGenerator (no Devart) and autogenerated dataadapters (CARDSTableAdapter, DOCUMENTSTableAdapter)
My code:
Code: Select all
Private Sub acceptCard()
Dim transaction As Devart.Data.Oracle.OracleTransaction = DataHelper.Connection.BeginTransaction()
Dim cardRow As DataRow = DirectCast(bsCards.Current, DataRowView).Row
Try
If cardRow.RowState = DataRowState.Detached Then
cardRow("ID") = DataHelper.CardsSequence.NextValue
cardRow("KOD_ORG") = Convert.ToInt32(DataHelper.OrganizationRow("ID"))
cardRow("STATUS") = "00000"
cardRow("USER_CREATE") = DataHelper.UserName
cardRow("DAT_CREATE") = DataHelper.GetSystemDate
Else
cardRow("USER_LAST") = DataHelper.UserName
cardRow("DAT_LAST") = DataHelper.GetSystemDate
End If
bsCards.EndEdit()
For Each documentsRow As DataRow In dsCards.DOCUMENTS.Select("", "", DataViewRowState.Added)
documentsRow("ID") = DataHelper.DocumentsSequence.NextValue()
documentsRow("ID_REP") = cardRow("ID")
Console.WriteLine("-" & documentsRow("ID_REP"))
Next
adpCards.Transaction = transaction
adpCards.Update(cardRow)
adpDocuments.Transaction = transaction
adpDocuments.Update(dsCards.DOCUMENTS)
transaction.Commit()
Me.CardReadOnly = True
RaiseEvent CardEditFinished(cardRow)
Catch ex As Exception
transaction.Rollback()
'..........................
End Try
End Sub
Adapter class from designer:
Code: Select all
Namespace CardsDataSetTableAdapters
'''
'''Represents the connection and commands used to retrieve and save data.
'''
_
Partial Public Class CARDSTableAdapter
Inherits Global.System.ComponentModel.Component
Private WithEvents _adapter As Global.Devart.Data.Oracle.OracleDataAdapter
Private _connection As Global.Devart.Data.Oracle.OracleConnection
Private _transaction As Global.Devart.Data.Oracle.OracleTransaction
Private _commandCollection() As Global.Devart.Data.Oracle.OracleCommand
Private _clearBeforeFill As Boolean
..........
End Class
Posted: Thu 22 Jan 2009 16:17
by Shalex
You didn't give us the definition of the DataHelper.Connection object whose the BeginTransaction() method is invoked.
Please send me (alexsh*devart*com) a small test project that reproduces the problem, include definitions of database objects (DDL) and avoid using third-party components. We will investigate the problem and notify you about the results.
Posted: Fri 23 Jan 2009 13:06
by Sergey Schukin
I am sorry, it was my bug:
to one of adapters had other Connection object.