SQL Server 提供的DTS API是一组COM组件,可以调用DTS相关功能
根据SQL Server帮助里的例子,改写成了Delphi执行DTS包
///uses ..COMObj;
var ObjPackage, ObjStep, ObjTask, ObjExecPkg: variant;begin ObjPackage := CreateOLEObject('DTS.Package2'); ObjPackage.failonerror := true; ObjStep := ObjPackage.steps.new; ObjTask := ObjPackage.tasks.new('DTSExecutePackageTask'); ObjExecPkg := ObjTask.customtask;
ObjExecPkg.PackagePassword := 'user'; ObjExecPkg.FileName := 'C:/DTS_UE/TestPkg/VarPubsFields.dts'; ObjExecPkg.Name := 'ExecPkgTask';
ObjStep.TaskName := objExecPkg.Name; ObjStep.Name := 'ExecPkgStep'; ObjStep.ExecuteInMainThread := True;
ObjPackage.Steps.Add(ObjStep); ObjPackage.Tasks.Add(ObjTask); ObjPackage.Execute;
ObjExecPkg := Null; ObjTask := Null; ObjStep := Null;
ObjPackage.UnInitialize;end;