Groups | Blog | Home
all groups > sql server clients > july 2003 >

sql server clients : Modifying a DTS package from Delphi


J O Holloway
7/31/2003 10:49:03 AM
For MS SQL Server 2000 and Delphi 5, I would like to access and change
global variables within a DTS package.

I can access the package and execute it, but I'm unclear on the syntax for
actually changing the global variable.

Any help would be much appreciated.

J O Holloway
7/31/2003 2:05:05 PM
Ok, I figured it out. Here's the code.

procedure TfmLoyalty.Button1Click(Sender: TObject);
var
FPackage : _Package;
strPackageName : string;

const
SQL_DATASOURCE = '(local)';
SQL_USERID = 'user';
SQL_PWD = 'somepassword';

begin
// this section gains access to the DTS package
FPackage := CoPackage.Create;
strPackageName := 'MyPackage';
FPackage.LoadFromSQLServer(
SQL_DATASOURCE,
WideString( SQL_USERID ),
WideString( SQL_PWD ),
DTSSQLStgFlag_Default,
WideString(''), //package password
WideString(''), //package guid
WideString(''), //package version guid
WideString( strPackageName ), //package name
EmptyParam //pVarPersistStgOfHost
);

// this line edits the variable
FPackage.GlobalVariables.Item('GVnumber1')._Set_Value(Edit1.text);

// this section saves the changes to the package on SQL Server
FPackage.SaveToSQLServer(
SQL_DATASOURCE,
WideString( SQL_USERID ),
WideString( SQL_PWD ),
DTSSQLStgFlag_Default,
WideString(''), //package owner password
WideString(''), //package operator password
WideString(''), //package category id
EmptyParam, //pVarPersistStgOfHost
TRUE //bReusePasswords
);

end;

[quoted text, click to view]

AddThis Social Bookmark Button