dbTalk Databases Forums  

Read GlobalVariable from package started from my code (C# .NET)

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Read GlobalVariable from package started from my code (C# .NET) in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mrozik
 
Posts: n/a

Default Read GlobalVariable from package started from my code (C# .NET) - 12-15-2003 , 08:27 AM







I have my custom task - and inside my class code:

public void Execute(object pPackage, object pPackageEvents, object
pPackageLog, ref Microsoft.SQLServer.DTSPkg80.DTSTaskExecResult
pTaskResult)
{
PackageLog packageLog = (PackageLog) pPackageLog;
Package2 package = (Package2) pPackage;
PackageEvents packageEvents = (PackageEvents) pPackageEvents;

package.GlobalVariables.Remove("MyData");
package.GlobalVariables.AddGlobalVariable("MyData" , "simple string
data");


And I run package which contains my custom task
form C# code:

object tmp = new object();
Microsoft.SQLServer.DTSPkg80.Package2 dtsp = new
Microsoft.SQLServer.DTSPkg80.Package2();
dtsp.LoadFromSQLServer("(local)",
"sa", "pwd",
DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", null, null,
"PPCustomTask",ref tmp );
dtsp.Execute();

dtsp.UnInitialize();
dtsp = null;


Everything goes right, but after line "dtsp.Execute();"
I want to read global variable "MyData" - code

dtsp.GlobalVariables.Item("MyData").Value.ToString ()

fails: error: 'dtsp.GlobalVariables' does not exist.
GlobalVariables collection contains no items...

What is wrong?

Pawel

Reply With Quote
  #2  
Old   
Darren Green
 
Posts: n/a

Default Re: Read GlobalVariable from package started from my code (C# .NET) - 12-15-2003 , 02:40 PM






In article <oprz77scgyy3yzc4 (AT) msnews (DOT) microsoft.com>, Mrozik
<mrozik.p (AT) interia (DOT) pl> writes
Quote:
I have my custom task - and inside my class code:

public void Execute(object pPackage, object pPackageEvents, object
pPackageLog, ref Microsoft.SQLServer.DTSPkg80.DTSTaskExecResult
pTaskResult)
{
PackageLog packageLog = (PackageLog) pPackageLog;
Package2 package = (Package2) pPackage;
PackageEvents packageEvents = (PackageEvents) pPackageEvents;

package.GlobalVariables.Remove("MyData");
package.GlobalVariables.AddGlobalVariable("MyData" ,
"simple string data");


And I run package which contains my custom task
form C# code:

object tmp = new object();
Microsoft.SQLServer.DTSPkg80.Package2 dtsp = new
Microsoft.SQLServer.DTSPkg80.Package2();
dtsp.LoadFromSQLServer("(local)",
"sa", "pwd",
DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", null, null,
"PPCustomTask",ref tmp );
dtsp.Execute();

dtsp.UnInitialize();
dtsp = null;


Everything goes right, but after line "dtsp.Execute();"
I want to read global variable "MyData" - code

dtsp.GlobalVariables.Item("MyData").Value.ToString ()

fails: error: 'dtsp.GlobalVariables' does not exist.
GlobalVariables collection contains no items...

What is wrong?

Pawel
The code itself looks OK, although I didn't build the custom task.
I get a different error though if my GV collection is empty or a I
reference the wrong name, "An unhandled exception of type
'System.NullReferenceException' occurred in DtsExecuteCSharp.exe". This
is using VS 2003.

Can you do anything with the GlobalVariables collection e.g.

Debug.WriteLine(dtsp.GlobalVariables.Count.ToStrin g());

My test harness was based on code from -
http://www.sqldev.net/dts/ExecutePac...isual%20Csharp
--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #3  
Old   
Mrozik
 
Posts: n/a

Default Re: Read GlobalVariable from package started from my code (C# .NET) - 12-16-2003 , 01:50 AM



On Mon, 15 Dec 2003 20:40:49 +0000, Darren Green
<darren.green (AT) reply-to-newsgroup-only (DOT) uk.com> wrote:

Quote:
In article <oprz77scgyy3yzc4 (AT) msnews (DOT) microsoft.com>, Mrozik
mrozik.p (AT) interia (DOT) pl> writes

I have my custom task - and inside my class code:

public void Execute(object pPackage, object pPackageEvents, object
pPackageLog, ref Microsoft.SQLServer.DTSPkg80.DTSTaskExecResult
pTaskResult)
{
PackageLog packageLog = (PackageLog) pPackageLog;
Package2 package = (Package2) pPackage;
PackageEvents packageEvents = (PackageEvents)
pPackageEvents;

package.GlobalVariables.Remove("MyData");
package.GlobalVariables.AddGlobalVariable("MyData" ,
"simple string data");


And I run package which contains my custom task
form C# code:

object tmp = new object();
Microsoft.SQLServer.DTSPkg80.Package2 dtsp = new
Microsoft.SQLServer.DTSPkg80.Package2();
dtsp.LoadFromSQLServer("(local)",
"sa", "pwd",
DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, "", null, null,
"PPCustomTask",ref tmp );
dtsp.Execute();

dtsp.UnInitialize();
dtsp = null;


Everything goes right, but after line "dtsp.Execute();"
I want to read global variable "MyData" - code

dtsp.GlobalVariables.Item("MyData").Value.ToString ()

fails: error: 'dtsp.GlobalVariables' does not exist.
GlobalVariables collection contains no items...

What is wrong?

Pawel

The code itself looks OK, although I didn't build the custom task.
I get a different error though if my GV collection is empty or a I
reference the wrong name, "An unhandled exception of type
'System.NullReferenceException' occurred in DtsExecuteCSharp.exe". This
is using VS 2003.

Can you do anything with the GlobalVariables collection e.g.

You are right - if I try line
Debug.WriteLine(dtsp.GlobalVariables.Count.ToStrin g());
I have the same error.
Before running
dtsp.Execute();
I can remove/add global variables to collection, but after
..Execute()m i can't read it - NullReferenceException occurs...
Pawel


Reply With Quote
  #4  
Old   
Darren Green
 
Posts: n/a

Default Re: Read GlobalVariable from package started from my code (C# .NET) - 12-16-2003 , 12:41 PM



In article <oprz9j2h0qy3yzc4 (AT) msnews (DOT) microsoft.com>, Mrozik
<mrozik.p (AT) interia (DOT) pl> writes
<snip>
Quote:
You are right - if I try line
Debug.WriteLine(dtsp.GlobalVariables.Count.ToStrin g());
I have the same error.
Before running
dtsp.Execute();
I can remove/add global variables to collection, but after
.Execute()m i can't read it - NullReferenceException occurs...
Pawel
Can you not even read the GlobalVariables collection Count property post
Execute?

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #5  
Old   
Mrozik
 
Posts: n/a

Default Re: Read GlobalVariable from package started from my code (C# .NET) - 12-17-2003 , 01:39 AM



On Tue, 16 Dec 2003 18:41:29 +0000, Darren Green
<darren.green (AT) reply-to-newsgroup-only (DOT) uk.com> wrote:

Quote:
In article <oprz9j2h0qy3yzc4 (AT) msnews (DOT) microsoft.com>, Mrozik
mrozik.p (AT) interia (DOT) pl> writes
snip

You are right - if I try line
Debug.WriteLine(dtsp.GlobalVariables.Count.ToStrin g());
I have the same error.
Before running
dtsp.Execute();
I can remove/add global variables to collection, but after
.Execute()m i can't read it - NullReferenceException occurs...
Pawel

Can you not even read the GlobalVariables collection Count property post
Execute?

After Execute I can not read any property
from GlobalVariables collection...
Pawel


Reply With Quote
  #6  
Old   
Darren Green
 
Posts: n/a

Default Re: Read GlobalVariable from package started from my code (C# .NET) - 12-17-2003 , 04:35 PM



In article <opr0bd75a3y3yzc4 (AT) msnews (DOT) microsoft.com>, Mrozik
<mrozik.p (AT) interia (DOT) pl> writes
Quote:
On Tue, 16 Dec 2003 18:41:29 +0000, Darren Green
darren.green (AT) reply-to-newsgroup-only (DOT) uk.com> wrote:

In article <oprz9j2h0qy3yzc4 (AT) msnews (DOT) microsoft.com>, Mrozik
mrozik.p (AT) interia (DOT) pl> writes
snip

You are right - if I try line
Debug.WriteLine(dtsp.GlobalVariables.Count.ToStrin g());
I have the same error.
Before running
dtsp.Execute();
I can remove/add global variables to collection, but after
.Execute()m i can't read it - NullReferenceException occurs...
Pawel

Can you not even read the GlobalVariables collection Count property
post Execute?


After Execute I can not read any property
from GlobalVariables collection...
Pawel
So after executing the package the GlobalVariables collection errors
when ever you try and read any values from it or even just the
collection Count property?

This is only when the package executed has your own custom task in it?

If so then I guess it has to be something to do with the task itself,
but I don't know what or why this would happen.

What about if you do the same remove and add process but in a normal
ActiveX Script Task? Does this work OK?

Perhaps you could try re-creating the original package just to make sure
it is "clean". Just guessing now as you can see

If it still just refuses to work when you use your custom task but the
tests without work fine, then there must be something it doesn't like,
possibly due to the use of .Net. Maybe you could look for an alternative
method to do what you want, without adding and removing global
variables? Perhaps you could explain what you want to achieve here?

If you could send me the custom task code as well it might be useful to
see if I can repro the problem here as well. I may try and get a bug
logged with MS, and they might have an answer but I wouldn't hold out
too much hope right now. (My email is darren at my domain name of the
site below.)

--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.