Applying DTs in C #

Source: Internet
Author: User
Applying DTs in C #

This article will focus on listing and executing DTS Packages and changing the attributes or global variables of DTS Packages.

First, let's take a look at how to list the local (local or (local) \ netsdk) servers that are saved as local packages. The key to processing DTS Packages in DOTNET is to add a reference to the "Microsoft dtspackage Object Library" (DTS. dll ).

Below Code List local packages on the server.

Static void main (string [] ARGs)
{
DTS. Application APP = new DTS. Application ();
DTS. packagesqlserver package = app. getpackagesqlserver ("(local) \ netsdk", "sa ","",
DTS. dtssqlserverstorageflags. dtssqlstgflag_default );
DTS. packageinfos Infos;
Infos = package. enumpackageinfos ("", false ,"");
Foreach (DTS. packageinfo info in Infos)
{
Console. writeline ("Name: {0} \ tversionid: {1}", info. Name, info. versionid );
}
Console. Read ();
}

The data transmission package attribute code for the formatted storage file is as follows:

Static void main (string [] ARGs)
{
DTS. package2class package = new DTS. package2class ();
DTS. savedpackageinfos Infos =
Package. getsavedpackageinfos ("C: \ pubs2pubs2package. DTS ");
Foreach (DTS. savedpackageinfo info in Infos)
{
Console. writeline ("Name: {0} \ tversionid: {1 }",
Info. packagename, info. versionid );
}
Package. uninitialize ();
Console. Read ();
}

You can use the package2class object to execute the DTS package or operate the attributes of the DTS package. The Code is as follows:

Static void main (string [] ARGs)
{
DTS. package2class package = new DTS. package2class ();
Try
{
Object Mia = system. reflection. Missing. value;
Package. loadfromsqlserver ("(local) \ netsdk ",
"Sa", "", DTS. dtssqlserverstorageflags. dtssqlstgflag_default ,"","",
"{F580DFC4-1F6A-4D70-B6A1-1C200B0D7890}", "customtaskpkg", ref Mia );
Console. writeline (package. Description );
Package. Description = "my description ";
Console. writeline (package. Description );
}
Catch (exception ex)
{
Console. writeline (ex. Message );
}
Finally
{
Package. uninitialize ();
Package = NULL;
}
Console. Read ();
}

If you want to use the latest version information, do not enter the version ID information. The Code is as follows:
Package. savetosqlserver ("(local) \ netsdk", "sa ","",
DTS. dtssqlserverstorageflags. dtssqlstgflag_default, "", "", ref Mia, false );

The following describes how to set the global variables of a data transmission package:
Static void main (string [] ARGs)
{
DTS. package2class package = new DTS. package2class ();
Try
{
Object Mia = system. reflection. Missing. value;
Package. loadfromstoragefile ("C: \ pubs2pubs2package. DTS ","","","",
"Pubs2pubs2package", ref Mia );
Package. globalvariables. addglobalvariable ("myvariable", "myvalue ");
Foreach (DTS. globalvariable gvar in package. globalvariables)
Console. writeline ("Name: {0} \ tvalue: {1}", gvar. Name, gvar. value );
}
Catch (exception ex)
{
Console. writeline (ex. Message );
}
Finally
{
Package. uninitialize ();
}
Console. Read ();
}

Modify the global variable value statement:
Package. globalvariables. Item ("myvariable"). let_value ("hello from C #");

The following statement saves the changes to the data transmission package.
Package. savetostoragefile ("C: \ pubs2pubs2package. DTS", "", ref Mia, false );

Execution package:
Package. Execute ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.