1、新建一个项目,添加SQLServer DSTS的COM引用,常用路径为c:\program files\microsoft sql server\80\tools\binn\dtspkg.dll
2、操作DTS的代码如下
A、列出所有数据库的包
ApplicationClass app = new ApplicationClass();
PackageSQLServer pkgSS = app.GetPackageSQLServer("localhost","","",DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection);
PackageInfos pkgInfos = pkgSS.EnumPackageInfos("",false,"");
PackageInfo pkgInfo = pkgInfos.Next();
txtLayOut.Text = "";
while(!pkgInfos.EOF)
{
txtLayOut.Text += pkgInfo.Name + "\r\n";
pkgInfo = pkgInfos.Next();
}
app = null;
B、执行一个指定的包
Package2Class pkg2 = new Package2Class();
object pVarPersistStgOfHost = null;
pkg2.LoadFromSQLServer("localhost", null, null,
DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, null,
null, null, "dtsTest2", ref pVarPersistStgOfHost);
pkg2.Execute();
pkg2.UnInitialize();
pkg2 = null;
C、新增一个包
Package2Class pkg2 = new Package2Class();
pkg2.Name = "dtsTest3";
object pVarPersistStgOfHost = null;
pkg2.SaveToSQLServer("localhost", null, null,
DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, null, null, null,
ref pVarPersistStgOfHost, true);
pkg2 = null;