on 10-03-2008 12:30 PM
Hi,
I am running the following code. While committing the transaction it's throwing an exception "there is no active transaction"
What could be the problem?
private void LoadObjectsFromXML() {
string sXmlFileName = null;
long iElementCount = 0;
long iCounter = 0;
// setting the file name
sXmlFileName = System.IO.Directory.GetParent( System.Windows.Forms.Application.StartupPath).ToString();
sXmlFileName = System.IO.Directory.GetParent( sXmlFileName).ToString() + @"\xml\BPandContacts.xml";
// Get the number of Business object in the file ...
iElementCount = oCompany.GetXMLelementCount( sXmlFileName );
Interaction.MsgBox( iElementCount + " Elemnts found in xml file" + Constants.vbNewLine + "Ready To Satrt Transaction", (Microsoft.VisualBasic.MsgBoxStyle)(0), null );
// start a transaction
// starting a transaction means that nothing changes in the DB
// untill we end the transaction with the commit flag
// if an error is encountered the transaction rolls back
// which means that all changes as of the StartTransaction
// are discarded
oCompany.StartTransaction();
// Run a loop through the objects and when with in the file
// and the objects to the DB
for ( iCounter=0; iCounter<=iElementCount - 1; iCounter++ ) {
// get the objects type at the specified position
oCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode;
switch ( oCompany.GetXMLobjectType( sXmlFileName, System.Convert.ToInt32( iCounter ) ) ) {
case SAPbobsCOM.BoObjectTypes.oBusinessPartners:
// get the business object data from the file
oBusinessPartner = ( ( SAPbobsCOM.BusinessPartners )( oCompany.GetBusinessObjectFromXML( sXmlFileName, System.Convert.ToInt32( iCounter ) ) ) );
// add the object to the data base
oBusinessPartner.Add();
break;
case SAPbobsCOM.BoObjectTypes.oItems:
// get the business object data from the file
oItem = ( ( SAPbobsCOM.Items )( oCompany.GetBusinessObjectFromXML( sXmlFileName, System.Convert.ToInt32( iCounter ) ) ) );
// add the object to the data base
oItem.Add();
break;
}
// Check for errors during connect
// if an error is encountered the transaction will
// terminate automatically
int transTemp0 = System.Convert.ToInt32( lErrCode );
oCompany.GetLastError( out transTemp0, out sErrMsg );
if ( lErrCode != 0 ) {
Interaction.MsgBox( "Error Message: " + sErrMsg + Constants.vbNewLine + "Transaction will be rolled back", (Microsoft.VisualBasic.MsgBoxStyle)(0), null );
// exiting the sub
return;
}
}
// the objects will added to the DB only at this point
oCompany.EndTransaction( SAPbobsCOM.BoWfTransOpt.wf_Commit );
Interaction.MsgBox( "Data inserted successfully", (Microsoft.VisualBasic.MsgBoxStyle)(0), null );
}
Hi
Try to use unique id for trasnaction...
VB code below need to be rewrited in C#... but only to have an idea
Sierdna S.
Dim oSqLTrans As SqlTransaction
Dim sTransactionName As String
Try
' BEGIN TRANSACTION
sTransactionName = "O99_" & DateTime.Now.Ticks.ToString
oSqLTrans = oSqlConn.BeginTransaction(sTransactionName)
' HERE DO SOMETHING ON DB ...
...
' COMMIT TRANSACTION
'DEBUG: oSqLTrans.Rollback(sTransactionName)
oSqLTrans.Commit()
Catch ex As Exception
If Not oSqLTrans Is Nothing Then
Try
' ROLLBACK TRANSACTION
oSqLTrans.Rollback(sTransactionName)
Catch sqlex As SqlException
If Not oSqLTrans.Connection Is Nothing Then
' log exception
End If
End Try
End If
Finally
oSqLTrans = Nothing
sTransactionName = Nothing
End Try
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
6 | |
5 | |
5 | |
5 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.