Apply DTS in C #

zhaozj2021-02-16  53

Apply DTS in C #

This article will focus on, perform DTS packets and change the properties of the DTS package or global variables.

First let's see how to list the local (local) server for the local (local) server. The key to handling the DTS package in the DOTNET is to add references to "Microsoft DTsPackage Object Library (DTS.DLL).

The following code can list the local package on the server.

Static void

Main

(String [] ARGS)

{

DTS.Application APP = New DTS.Application ();

DTS.Packagesql Server 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 attribute code saved in the format 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 ();

}

DTS packets can be performed by the Package2Class object, or the properties of the DTS package are operated. code show as below:

Static void

Main

(String [] ARGS)

{

DTS.Package2Class Package = new dts.package2class ();

Try

{

Object mia = system.reflection.Missing.Value;

Package.Loadfromsql Server ("(local) // netsdk,

"sa", ", dts.dtsqlserverStorageFlags.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, don't fill in the version ID information, the code is as follows:

Package.savetosql Server ("(local) // netsdk", "sa", "",

DTS.DTSSQLSERVERSTORAGEFLAGS.DTSSQLSTGFLAG_DEFAULT, "", "", "", ref mia, false);

The following is the process of setting 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 ();

}

Modify the global variable statement:

Package.globalvariables.Item ("MyVariable"). Let_Value ("Hello from C #");

The following statement will be saved in the DTS package.

Package.savetOStoragefile ("C: //pubs2pubs2package.dts", ",", ", ref mia, false);

Execute package:

Package.execute ();

转载请注明原文地址:https://www.9cbs.com/read-22522.html

New Post(0)