adapter.Save returns "false" but INSERT worked

Posts   
 
    
Posts: 94
Joined: 26-Feb-2006
# Posted on: 15-Mar-2006 00:05:22   

Hey All !

Just a newbie question: Under what cirumstances does adapter.SaveEntity(entity,true) return false??

The case is that it returns false but everything seems to be allright with inserted/updated rows in the DB and no exception is thrown.

I am using Firebird / Firebird.net 1.7A my code looks like this:

(please let me know I you find any WTFs! ;-)

    'preprocess entity before saving to Database
    If (entity.IsDirty And Not entity.IsNew) Then
        '(AUDIT) write changes and original values to a XML Document
          entity.WriteXml(XmlFormatAspect.DatesInXmlDataType, xmldoc)
    End If
    

                If(adapter.SaveEntity(entity, True)) Then
                'Write success message to Logfile
                WriteLog(Me.UMO001NR, Me.CODE, TranslationManager.GetLocalErrorMessageString("SAVEUMO211SUCCESS",Me.Language), Nothing, Me.SessionID, xmldoc)
                Return True
                Else
                Return False
                End If
                
             Catch eORM As ORMQueryExecutionException
            'Write Exception to logfile
            WriteLog(Me.UMO001NR, Me.CODE, TranslationManager.GetLocalErrorMessageString("SAVEUMO211ERROR",Me.Language), eORM.Message, Me.SessionID, xmldoc)
            Return False
            Catch ex As Exception
            'Write Exception to logfile
            WriteLog(Me.UMO001NR, Me.CODE, TranslationManager.GetLocalErrorMessageString("SAVEUMO211ERROR",Me.Language), ex.Message, Me.SessionID, xmldoc)
            Return False
            Finally
                adapter.CloseConnection()
                adapter.Dispose()
            End Try
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Mar-2006 08:03:08   

SaveEntity returns false when the saving fails.

Would you please specify the RuntimeLibrary version you are using?

Thanks.

Posts: 94
Joined: 26-Feb-2006
# Posted on: 15-Mar-2006 15:44:55   

Thanks for your support...

My Runtime version is1.02005.1 Final March 2nd 2006

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 16-Mar-2006 11:32:21   

Could you please post the whole routine? You cut/paste code which miss the start of the try, the open call to the connection, if you started your own transaction or not etc.

Also please remove the Return False from the catch clauses and replace them with throw statements, so you bubble up the exception.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 94
Joined: 26-Feb-2006
# Posted on: 16-Mar-2006 14:47:32   

Thank you very much Frans,

here is the whole routine.

I want to return false or true because I do not want the GUI facade to handle Execptions.

    ''' <summary>
    ''' Adds or updates information in the database
    ''' </summary>
    ''' <returns>Returns True if saved successfully, False otherwise.</returns>
    Function SaveUMO211Entity(ByVal entity As UMO211Entity) As Boolean

        Dim xmldoc As String
        Dim adapter As DataAccess.DatabaseSpecific.DataAccessAdapter

            Try
            
            adapter = New DataAccess.DatabaseSpecific.DataAccessAdapter
                    
    'preprocess entity before saving to Database
    If (entity.IsDirty And Not entity.IsNew) Then

    'update UMO replication fields
        
        '(AUDIT) write changes and original values to a XML Document
          entity.WriteXml(XmlFormatAspect.DatesInXmlDataType, xmldoc)
    End If
    
    'set foreign LOCATIE Value
If Not entity.TestCurrentFieldValueForNull(UMO211FieldIndex.UMO200LOC) Then
entity.UMO200LOC = TypedListProvider.GetLocatie() 
End If

'set foreign LOCATIE Value
If Not entity.TestCurrentFieldValueForNull(UMO211FieldIndex.UMO152LOC) Then
entity.UMO152LOC = TypedListProvider.GetLocatie() 
End If

    

                If(adapter.SaveEntity(entity, True)) Then
                'Write Success Message to Logfile
                WriteLog(Me.UMO001NR, Me.CODE, TranslationManager.GetLocalErrorMessageString("SAVEUMO211SUCCESS",Me.Language), Nothing, Me.SessionID, xmldoc)
                Return True
                Else
                Return False
                End If
                
             Catch eORM As ORMQueryExecutionException
            'Write Exception to Logfile
            WriteLog(Me.UMO001NR, Me.CODE, TranslationManager.GetLocalErrorMessageString("SAVEUMO211ERROR",Me.Language), eORM.Message, Me.SessionID, xmldoc)
            Return False
            Catch ex As Exception
            'Write Exception to Logfile
            WriteLog(Me.UMO001NR, Me.CODE, TranslationManager.GetLocalErrorMessageString("SAVEUMO211ERROR",Me.Language), ex.Message, Me.SessionID, xmldoc)
            Return False
            Finally
                adapter.CloseConnection()
                adapter.Dispose()
            End Try
    End Function