Applying DTS in C #

Source: Internet
Author: User
Tags foreach reflection
Applying DTS in C #



This article will focus on listing, executing DTS packages, and changing the properties of DTS packages or global variables.



Let's take a look at how to list the local packages that are saved locally (local) \NetSDK servers. The key to working with DTS packages in dotnet is to increase the reference to the Microsoft dtspackage Object Library (Dts.dll).



The following code can list the 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 ();

}



Take the DTS package Property code saved in the formatted storage file 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 ();

}



The Package2class object allows you to execute a DTS package or manipulate the properties of a 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 fill out the version ID information, the code is as follows:

Package. SaveToSQLServer ("(local) \\NetSDK", "sa", "",

Dts. Dtssqlserverstorageflags.dtssqlstgflag_default, "", "", "", ref Mia,false);



The following is the process of setting up a DTS package global variable:

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 ();

}



To modify a global variable value statement:

Package. Globalvariables.item ("myvariable"). Let_value ("Hello from C #");



The following statement saves the changes to the DTS package.

Package. SaveToStorageFile ("C:\\pubs2pubs2package.dts", "" "," "", ref Mia,false);



Execute 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.