Failed to lock variable "User::Variable" for read/write access with error 0xC0010001
I'm trying to set a variable on a parent package and I'm getting this error:
Error: 0xC0014055 at Post Upload:
Failed to lock variable "User::Variable" for read/write access with error 0xC0010001
"The variable cannot be found.
This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there.
The variable name may have changed or the variable is not being created.".
I can see and write the variable in the Visual Studio Watch window.
What am I doing wrong?
Paulo Morgado
August 19th, 2010 2:24pm
Can you share your code please?http://sqlblog.com/blogs/jamie_thomson/ |
@jamiet |
About me
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2010 3:11pm
Are you trying to set a parent package variable from child package?
The variable name is case sensitive ensure that the name is exactly the same. or better the copy the variable nme and put it in script task. Are you trying to do this in a script component?
August 19th, 2010 3:17pm
Or is it that any other child package is using the variable hence these is a conflict and you are getting an erro?
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2010 3:22pm
@Sudeep,
Yes, I'm trying to set a parent package variable from a child package.
@Jamie,
The value of ReadOnlyVariables for the tak is Local::Variable and the value of
ReadWriteVariables for the tak is User::Variable and the code is:
public void Main()
{
this.Dts.Variables["User::Variable"].Value = this.Dts.Variables["Local::Variable"].Value;
this.Dts.TaskResult = (int)ScriptResults.Success;
}
What am I doing wrong?Paulo Morgado
August 19th, 2010 3:24pm
@Sudeep,
Yes, I'm trying to set a parent package variable from a child package.
Aha. This won't work then. If you want to reference a variable in a parent package then you need to do the locking/unlocking using code - you can't use ReadWriteVariables (in my opinion you should never use ReadWriteVariables/ReadOnlyVariables properties
anyway - but others may disagree).
-Jamiehttp://sqlblog.com/blogs/jamie_thomson/ |
@jamiet |
About me
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2010 3:43pm
Check this link:
http://agilebi.com/cs/blogs/jwelch/archive/2009/10/03/passing-an-object-from-a-parent-package-to-a-child.aspx#comments
Please read the comments also.Nitesh Rai- Please mark the post as answered if it answers your question
August 19th, 2010 3:52pm
@Sudeep,
Yes, I'm trying to set a parent package variable from a child package.
Aha. This won't work then. If you want to reference a variable in a parent package then you need to do the locking/unlocking using code - you can't use ReadWriteVariables (in my opinion you should never use ReadWriteVariables/ReadOnlyVariables properties
anyway - but others may disagree).
-Jamie
http://sqlblog.com/blogs/jamie_thomson/ |
@jamiet |
About me
Hi Jamie,
I just created a simple package. Parent has a variable and the Execute package task which calls the child pcakage.
In the child package I have a Script task which updates the variable in the parent package and it works.
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2010 4:01pm
@Nitesh, @Sudeep,
As expected, I had a type "ImportFile" in one place, "FileImport" in the other. Sorry for the trouble.
@Jamie,
Why do you think ReadWriteVariables/ReadOnlyVariables properties should never be used?Paulo Morgado
August 19th, 2010 5:15pm
@Jamie,
Why do you think ReadWriteVariables/ReadOnlyVariables properties should never be used?
Because of this: http://www.sqlis.com/sqlis/post/A-deadlock-was-detected-while-trying-to-lock-variables-in-SSIS.aspx
Locking/Ulocking in code minimises the chance of variable deadlock.
Not everyone agrees with me - they say only do locking/unlocking in code if you actually have to. I prefer a safety-first approach.http://sqlblog.com/blogs/jamie_thomson/ |
@jamiet |
About me
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2010 6:02pm
Got it, Jamie.
What would be nice was the hability to provide a type for the base script class. If I could tell SSIS to use MyScriptComponent instead of ScriptComponent.
For now, I'm using some custom component that mimics the ScriptComponent and automates what I want to do in every script component, but it doesn't prevent the base ScriptComponent from doing what it wants.Paulo Morgado
August 19th, 2010 6:20pm
"you can't use ReadWriteVariables"? Huh? Why would you say that when its clearly not true as I do this all the time.
Maybe its good practice to manually lock and unlock variables but I'd like to know more about that before I go to the extra work. Plus I like seeing the variable list I'm updating in the read/write parameters.
I use them for parent variables, in a sense as global variables, to be updated from multiple child packages. I even keep parent row count and add to it from each child package. No parent package configuration needed. I have no problems doing this. However,
I have had odd behavior at times where I've had to literally copy/paste the parent variable name into the read/write variable list (with prefix of "User::" of course) to make it work even though I swear they were in appearance spelled/case exactly
the same.
I SURE WISH MICROSOFT WOULD CREATE GLOBAL PARAMETERS!!! Looks like Denali is supposed to have project level parameters. Lets just hope that the provide a prefix so we can more easily distinguish them from local variables. The way it works now is really quite
clumsy.Gary Melhaff, DW Architect, MCTS SqlServer 2008 BI, Developer
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2011 7:07pm