dbTalk Databases Forums  

dts works from Sql but fails using C#

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


Discuss dts works from Sql but fails using C# in the microsoft.public.sqlserver.dts forum.



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

Default dts works from Sql but fails using C# - 11-02-2003 , 09:00 AM






Hi:

I've covered a number of newsgroups and web sites today, but still cannot
seem to find out why my DTS package (which works fine via SQL) fails to work
correctly when I execute it from a C# program.
Here is the code I use:


object pVarPersistStgOfHost = null;

string val;


try

{

//pkg.LoadFromSQLServer("(Local)", "sa","",0, "", "","", "authorsTest",ref
pVarPersistStgOfHost);

pkg.LoadFromSQLServer("(local)",
"sa","",DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag _Default, "", "","",
"authorsTest",ref pVarPersistStgOfHost);

val=pkg.GlobalVariables.Item("city").Value.ToStrin g();

label1.Text=val;

pkg.GlobalVariables.Remove("city");

DTS.GlobalVariable gv=pkg.GlobalVariables.New("city");

gv.Value="Oakland";

//pkg.GlobalVariables.Item("city").Value="Oakland";

pkg.GlobalVariables.Add(gv);

label1.Text+=" *** "+pkg.GlobalVariables.Item("city").Value.ToString( );

pkg.Execute();

pkg.UnInitialize();

label1.Text+=" **** Success !!";

}

catch (Exception ex)

{

label1.Text=ex.ToString();

}



The label always displays the correct values too, but the spreadsheet
(except for the column headers, is empty....no data returned)



Thanks in advance for any help



Ken



Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: dts works from Sql but fails using C# - 11-03-2003 , 02:26 AM






Have a look at these couple of articles/sites


DTS Global Variables and Visual Basic .Net
(http://www.sqldts.com/default.aspx?265)

Converting a DTS Package from Visual Basic 6.0 to Visual Basic .Net
(http://www.sqldts.com/default.aspx?264)

http://www.sqldev.net/dts/DotNETCookBook.htm

--
--

Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"Keng" <nospam (AT) nospam (DOT) com> wrote

Quote:
Hi:

I've covered a number of newsgroups and web sites today, but still cannot
seem to find out why my DTS package (which works fine via SQL) fails to
work
correctly when I execute it from a C# program.
Here is the code I use:


object pVarPersistStgOfHost = null;

string val;


try

{

//pkg.LoadFromSQLServer("(Local)", "sa","",0, "", "","", "authorsTest",ref
pVarPersistStgOfHost);

pkg.LoadFromSQLServer("(local)",
"sa","",DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag _Default, "", "","",
"authorsTest",ref pVarPersistStgOfHost);

val=pkg.GlobalVariables.Item("city").Value.ToStrin g();

label1.Text=val;

pkg.GlobalVariables.Remove("city");

DTS.GlobalVariable gv=pkg.GlobalVariables.New("city");

gv.Value="Oakland";

//pkg.GlobalVariables.Item("city").Value="Oakland";

pkg.GlobalVariables.Add(gv);

label1.Text+=" *** "+pkg.GlobalVariables.Item("city").Value.ToString( );

pkg.Execute();

pkg.UnInitialize();

label1.Text+=" **** Success !!";

}

catch (Exception ex)

{

label1.Text=ex.ToString();

}



The label always displays the correct values too, but the spreadsheet
(except for the column headers, is empty....no data returned)



Thanks in advance for any help



Ken





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

Default Re: dts works from Sql but fails using C# - 11-03-2003 , 10:06 AM



I've been to those sites.....tried the sample code......doesn't work
on three different computers.

Thanks for the reply..




"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
Have a look at these couple of articles/sites


DTS Global Variables and Visual Basic .Net
(http://www.sqldts.com/default.aspx?265)

Converting a DTS Package from Visual Basic 6.0 to Visual Basic .Net
(http://www.sqldts.com/default.aspx?264)

http://www.sqldev.net/dts/DotNETCookBook.htm

--
--

Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"Keng" <nospam (AT) nospam (DOT) com> wrote in message
news:ugU6$HVoDHA.2404 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Hi:

I've covered a number of newsgroups and web sites today, but still cannot
seem to find out why my DTS package (which works fine via SQL) fails to
work
correctly when I execute it from a C# program.
Here is the code I use:


object pVarPersistStgOfHost = null;

string val;


try

{

//pkg.LoadFromSQLServer("(Local)", "sa","",0, "", "","", "authorsTest",ref
pVarPersistStgOfHost);

pkg.LoadFromSQLServer("(local)",
"sa","",DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag _Default, "", "","",
"authorsTest",ref pVarPersistStgOfHost);

val=pkg.GlobalVariables.Item("city").Value.ToStrin g();

label1.Text=val;

pkg.GlobalVariables.Remove("city");

DTS.GlobalVariable gv=pkg.GlobalVariables.New("city");

gv.Value="Oakland";

//pkg.GlobalVariables.Item("city").Value="Oakland";

pkg.GlobalVariables.Add(gv);

label1.Text+=" *** "+pkg.GlobalVariables.Item("city").Value.ToString( );

pkg.Execute();

pkg.UnInitialize();

label1.Text+=" **** Success !!";

}

catch (Exception ex)

{

label1.Text=ex.ToString();

}



The label always displays the correct values too, but the spreadsheet
(except for the column headers, is empty....no data returned)



Thanks in advance for any help



Ken



Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: dts works from Sql but fails using C# - 11-03-2003 , 10:09 AM



Errors ?


"KenG" <keng (AT) themailroom (DOT) com> wrote

Quote:
I've been to those sites.....tried the sample code......doesn't work
on three different computers.

Thanks for the reply..




"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Have a look at these couple of articles/sites


DTS Global Variables and Visual Basic .Net
(http://www.sqldts.com/default.aspx?265)

Converting a DTS Package from Visual Basic 6.0 to Visual Basic .Net
(http://www.sqldts.com/default.aspx?264)

http://www.sqldev.net/dts/DotNETCookBook.htm

--
--

Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

"Keng" <nospam (AT) nospam (DOT) com> wrote in message
news:ugU6$HVoDHA.2404 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
Hi:

I've covered a number of newsgroups and web sites today, but still
cannot
seem to find out why my DTS package (which works fine via SQL) fails
to
work
correctly when I execute it from a C# program.
Here is the code I use:


object pVarPersistStgOfHost = null;

string val;


try

{

//pkg.LoadFromSQLServer("(Local)", "sa","",0, "", "","",
"authorsTest",ref
pVarPersistStgOfHost);

pkg.LoadFromSQLServer("(local)",
"sa","",DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag _Default, "", "","",
"authorsTest",ref pVarPersistStgOfHost);

val=pkg.GlobalVariables.Item("city").Value.ToStrin g();

label1.Text=val;

pkg.GlobalVariables.Remove("city");

DTS.GlobalVariable gv=pkg.GlobalVariables.New("city");

gv.Value="Oakland";

//pkg.GlobalVariables.Item("city").Value="Oakland";

pkg.GlobalVariables.Add(gv);

label1.Text+=" ***
"+pkg.GlobalVariables.Item("city").Value.ToString( );

pkg.Execute();

pkg.UnInitialize();

label1.Text+=" **** Success !!";

}

catch (Exception ex)

{

label1.Text=ex.ToString();

}



The label always displays the correct values too, but the spreadsheet
(except for the column headers, is empty....no data returned)



Thanks in advance for any help



Ken





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

Default Re: dts works from Sql but fails using C# - 11-03-2003 , 12:29 PM



In article <3d7721e9.0311030806.517bae16 (AT) posting (DOT) google.com>, KenG
<keng (AT) themailroom (DOT) com> writes
Quote:
I've been to those sites.....tried the sample code......doesn't work
on three different computers.

Thanks for the reply..


How do you know if the package works or not?

You don't, all you know is that you loaded a package and you executed
it,, not the result of that execution at either a package or individual
task or step level.

Have a look at each step object and check the ExecutionResult and
preferably call the GetExecutionErrorInfo method for the full error
message.


--
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
  #6  
Old   
Prem
 
Posts: n/a

Default Re: dts works from Sql but fails using C# - 11-07-2003 , 10:36 AM



Ken,

I faced the same problem you did, and found an answer at a website I
now plan to frequent:
http://www.c-sharpcorner.com/Code/2002/Sept/DTSnCS.asp


At any rate, it boils down to using the "let_value" method off the
GlobalVariables.Item object. So to set a global variable's value you'd
do the following:

objDTSPkg.GlobalVariables.Item("MyGlobalVariable") .let_value("NewValue");


What I also found (I'm not sure why this is so) is that when you use
this method,there is no need to remove and re-add the global variable
from the package. So I just did a

objDTSPkg.LoadFromSQLServer

and then used the let_value method directly.

Hope this helps.

Prem Isaac
creationmatters (AT) yahoo (DOT) com

"Keng" <nospam (AT) nospam (DOT) com> wrote

Quote:
Hi:

I've covered a number of newsgroups and web sites today, but still cannot
seem to find out why my DTS package (which works fine via SQL) fails to work
correctly when I execute it from a C# program.
Here is the code I use:


object pVarPersistStgOfHost = null;

string val;


try

{

//pkg.LoadFromSQLServer("(Local)", "sa","",0, "", "","", "authorsTest",ref
pVarPersistStgOfHost);

pkg.LoadFromSQLServer("(local)",
"sa","",DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag _Default, "", "","",
"authorsTest",ref pVarPersistStgOfHost);

val=pkg.GlobalVariables.Item("city").Value.ToStrin g();

label1.Text=val;

pkg.GlobalVariables.Remove("city");

DTS.GlobalVariable gv=pkg.GlobalVariables.New("city");

gv.Value="Oakland";

//pkg.GlobalVariables.Item("city").Value="Oakland";

pkg.GlobalVariables.Add(gv);

label1.Text+=" *** "+pkg.GlobalVariables.Item("city").Value.ToString( );

pkg.Execute();

pkg.UnInitialize();

label1.Text+=" **** Success !!";

}

catch (Exception ex)

{

label1.Text=ex.ToString();

}



The label always displays the correct values too, but the spreadsheet
(except for the column headers, is empty....no data returned)



Thanks in advance for any help



Ken

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.