You are viewing limited content. For full access, please sign in.

Question

Question

DocMetaData.LockObject and DocMetaData.Field give error "Invalid connection."

SDK
asked on July 12, 2017 Show version history

I have a function to change a field name using DocMetaData.Field which always works, except for this new situation, which occurs after a CreateCopyOf. The error occurs in the second function.  Here is the code, which I hope is clear -

oLaserfiche.CopyDocumentWithTemplate(4, lfDoc, sLfRepository, lfDoc.FullPath, lfDoc.Name, "_Copy1")
iNewTocId = lfDoc.ID
oLaserfiche.UpdateLaserficheDocumentFieldValue("Type", sType, lfDoc)
 


'Called function #1 -
Public Sub CopyDocumentWithTemplate(ByVal ApplicationId As String,
          ByRef lfDoc As LFDocument,
          ByVal sLfRepository As String,
          ByVal FolderPath As String,
          ByVal FileName As String,
          ByVal NewFileNameSuffix As String)
Dim Application As String = String.Empty
Dim ReturnedMessage As String = String.Empty
Dim ActiveRepository As LFDatabase = Nothing
Dim CurrentDoc As LFDocument = Nothing
Dim ParentFolder As LFFolder = Nothing
Dim CopyDoc As New LFDocument
Dim iApplicationId As Integer = 0
Dim iTocID As Integer = 0

If FolderPath <> "" Then
 Try
  ActiveRepository = InitializeLaserficheConnection()
  CurrentDoc = New LFDocument
  CurrentDoc = ActiveRepository.GetEntryByPath(FolderPath)
  ParentFolder = ActiveRepository.GetEntryByPath(sLfRepository & FolderPath.Replace("\" & FileName, ""))

  CopyDoc.CreateCopyOf(CurrentDoc, FileName & NewFileNameSuffix, ParentFolder, True)
  CopyDoc.Update()
  lfDoc = CopyDoc

 Catch ex As Exception
  ReturnedMessage = "CopyDocumentWithTemplate. Error - " & ex.Source & "<br/> " & ex.Message
 Finally
  If Not CurrentDoc Is Nothing Then
   CurrentDoc.Dispose()
  End If
  If Not CopyDoc Is Nothing Then
   CopyDoc.Dispose()
  End If
  If Not ActiveRepository Is Nothing Then
   DisconnectLaserficheConnection(ActiveRepository)
   ActiveRepository = Nothing
  End If
 End Try
End If

End Sub

 

'Called function #2 -
Public Function UpdateLaserficheDocumentFieldValue(ByVal sFieldName As String, _
             ByVal sFieldValue As String, _
             ByRef lfDoc As LFDocument) As Boolean
Dim DocMetaData As LFFieldData = Nothing
Dim bReturn As Boolean = True

Try
 DocMetaData = lfDoc.FieldData()

 If Not DocMetaData.IsLocked Then
  'NEXT LINE HAS ERROR!
  DocMetaData.LockObject(Lock_Type.LOCK_TYPE_WRITE)
 End If
  'NEXT LINE HAS ERROR if I skip LockObject
 DocMetaData.Field(sFieldName) = sFieldValue
 DocMetaData.Update()

Catch ex As Exception
 ex.Source &= m_csModName & ".UpdateLaserficheDocumentFieldValue" & vbNewLine
 Throw
 bReturn = False

Finally
 If DocMetaData.IsLocked Then
  DocMetaData.UnlockObject()
 End If

End Try

Return bReturn
End Function

 

I greatly appreciate any help.

Howard

0 0

Answer

SELECTED ANSWER
replied on July 13, 2017

I see the problem now, you are closing the connection to laserfiche in the call to DisconnectLaserficheConnection. My code commented that out because that function isn't included in the sample.

1 0

Replies

replied on July 12, 2017

We are using Laserfiche Server 10.1.1 build 254.

The VB.Net code has -

Imports LFSO100Lib

Imports DocumentProcessor100.

 

I think there may be a problem with -

lfDoc = CopyDoc

but the new ID is found in -

iNewTocId = lfDoc.ID

0 0
replied on July 12, 2017

I think the problem is that you are calling Dispose() on CopyDoc before it is used again in function #2. I tried the code and I can't reproduce the problem.

0 0
replied on July 12, 2017

Thanks for your reply Robert.

But I still get "Invalid connection." on the LockObject, even if I remove CopyDoc.Dispose().

And actually, CopyDoc is a local LFDocument variable in function #1.

Do you see any problems with this - lfDoc = CopyDoc ?

0 0
SELECTED ANSWER
replied on July 13, 2017

I see the problem now, you are closing the connection to laserfiche in the call to DisconnectLaserficheConnection. My code commented that out because that function isn't included in the sample.

1 0
replied on July 13, 2017

Yes, your first function creates and then terminates a connection to the repository.  Your second function does not have a connection.

1 0
replied on July 13, 2017

Thank you Robert & Bert!!

Yes, I took out that call to DisconnectLaserficheConnection and it now works!

I was thinking that this function was it's own world, but forgot that disconnecting in LF disconnects the main connection too.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.