none
A deadlock was detected while trying to lock variables RRS feed

  • Question

  •  

    Hi Friends,

     

    I have a problem to read varibale inside script.

    the error discription is following-

     

    Error: A deadlock was detected while trying to lock variables "User::FilePath" for read/write access. A lock cannot be acquired after 16 attempts. The locks timed out.

     

     

    this is my code. i my code i am using two variables, but i can access only one .

    i have to retrive file directory and file path is generated by other system.

     

    Public Sub Main()

    '

    ' Add your code here

    '

    Dim vars As Variables

     

    If Not vars Is Nothing Then

    vars.Unlock()

    End If

    Dim lFileName As String = String.Empty

    Dim lFilePath As String = String.Empty

    Dts.VariableDispenser.LockOneForWrite("FilePath", vars)

    Dts.VariableDispenser.LockOneForRead("FileName", vars)

    Dts.VariableDispenser.GetVariables(vars)

    lFileName = vars.Item("FileName").Value.ToString

    lFilePath = GetDirectoryName(lFileName)

    If Not lFilePath.EndsWith("\") Then

    lFilePath = String.Format("{0}\", lFilePath)

    End If

    vars("UnzippedKeyStatFilePath").Value = lFilePath

    vars.Unlock()

    Dts.TaskResult = Dts.Results.Success

     

    End Sub

     

    Thanks

    Manish Jain

    Thursday, March 20, 2008 5:10 PM

Answers

  • If you've put the variable in the ReadOnlyVariables or ReadWriteVariables properties on the script task, you need to remove it. When you explicitly handle locking (which is the better option), you don't need to include it there, or it tries to lock it twice.

    Thursday, March 20, 2008 10:10 PM
    Moderator
  • Also, you shouldn't be using LockOneForRead if you want to access two variables. Instead, use the LockForRead or LockForWrite, and then the GetVariables method:

     

    Code Snippet

    Dts.VariableDispenser.LockForWrite("FilePath")

    Dts.VariableDispenser.LockForRead("FileName")

    Dts.VariableDispenser.GetVariables(vars)

     

     

    Thursday, March 20, 2008 10:14 PM
    Moderator

All replies

  • If you've put the variable in the ReadOnlyVariables or ReadWriteVariables properties on the script task, you need to remove it. When you explicitly handle locking (which is the better option), you don't need to include it there, or it tries to lock it twice.

    Thursday, March 20, 2008 10:10 PM
    Moderator
  • Also, you shouldn't be using LockOneForRead if you want to access two variables. Instead, use the LockForRead or LockForWrite, and then the GetVariables method:

     

    Code Snippet

    Dts.VariableDispenser.LockForWrite("FilePath")

    Dts.VariableDispenser.LockForRead("FileName")

    Dts.VariableDispenser.GetVariables(vars)

     

     

    Thursday, March 20, 2008 10:14 PM
    Moderator