Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum New-PWDocumentVersion - database deadlock error?
    • Sign In

    • State Not Answered
    • Replies 8 replies
    • Subscribers 67 subscribers
    • Views 4662 views
    • Users 0 members are here
    • new-pwdocumentversion
    • error
    • pwps_dab

    New-PWDocumentVersion - database deadlock error?

    Jim Turner
    Jim Turner over 4 years ago

    I have a script to synchronize files in a server folder with documents in a ProjectWise folder.   I have several thousands of documents to sync so I have 'powershelled' the task.

    One of my commands is to create a new document version:

    Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile  | New-PWDocumentVersion -VersionString $verString | Out-Null

    This will happily run for long periods of time, and then fall over for no apparent reason: 

    New-PWDocumentVersion : Error changing document 'FILENAME' to new
    version. Error creating new version of document.At SCRIPTNAME1:548 char:97
    + ... e $theFile | New-PWDocumentVersion -VersionString $verString | Out-N ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (Version:String) [New-PWDocumentVersion], Exception
    + FullyQualifiedErrorId : ErrorID: Database transaction deadlock error.,PWPS_DAB.NewPWDocumentVersion

    What is a database transaction deadlock error and how to prevent it?  For the record, the $verString is set to "P02" and the previous version is "P01".

    Thanks for any help.  

    • Sign in to reply
    • Cancel

    Top Replies

    • Kevin van Haaren
      Offline Kevin van Haaren Tue, Jan 22 2019 2:43 PM in reply to Kevin van Haaren +1
      probably slightly more performant to capture the file in a variable: $fileObj = Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile try { $fileObj | New-PWDocumentVersion -VersionString…
    • Dean Lyon
      0 Offline Dean Lyon Tue, Jan 22 2019 11:48 AM

      A deadlock error occurs when a the row of the database is locked by one thread and another thread is attempting to lock the row. Since ProjectWise transactions are pooled into one thread from the Integration server, I would assume that either another program is accessing the database at the same time as ProjectWise. You need to involve your DBA to determine what thread has the lock and is causing the deadlock to occur.

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Jim Turner
      0 Jim Turner Tue, Jan 22 2019 12:02 PM in reply to Dean Lyon

      Thank you.  That is a mystery as I can't think what other program would be accessing at the same time. 

      As it's managed service - I imagine our DBA is Bentley;  PowerShell queries however get directed to the forum.  Bit stuck on this one!

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Brian Flaherty
      0 Offline Brian Flaherty Tue, Jan 22 2019 2:39 PM

      Is it possible the document  you are attempting to create a new version for, is either checked out, exported, or set to final status?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Tue, Jan 22 2019 2:41 PM in reply to Jim Turner

      I don't know what might be causing the deadlock, but if you want to script around it, you can use a Try/Catch block to catch the error, maybe add a pause and then retry.

      try {
          Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile  | New-PWDocumentVersion -VersionString $verString | Out-Null
      } catch {
          write-error "create new version failed, retrying"
          start-sleep -seconds 10
          Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile  | New-PWDocumentVersion -VersionString $verString | Out-Null
      }
      

      details on try/catch here:

      https://www.vexasoft.com/blogs/powershell/7255220-powershell-tutorial-try-catch-finally-and-error-handling-in-powershell

      and here:

      https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_try_catch_finally?view=powershell-6

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Tue, Jan 22 2019 2:43 PM in reply to Kevin van Haaren

      probably slightly more performant to capture the file in a variable:

      $fileObj = Get-PWDocumentsBySearch -FolderPath $pwfolder -FileName $theFile
      try {
          $fileObj  | New-PWDocumentVersion -VersionString $verString | Out-Null
      } catch {
          write-error "create new version failed, retrying"
          start-sleep -seconds 10
          $fileObj  | New-PWDocumentVersion -VersionString $verString | Out-Null
      }
      

       

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    >

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies