关于客户端编码 DTS ,大家请看我这段代码有什么问题呀? ( 积分: 100 )

  • 主题发起人 主题发起人 jacky_20001
  • 开始时间 开始时间
J

jacky_20001

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TFrmMain.BitBtn3Click(Sender: TObject);
procedure oCustomTask2_Trans_S1(oCustomTask2: DataPumpTask2);
var
oTransformationOld: Transformation;
oTransformation: Transformation2;
begin
oTransformationOld := oCustomTask2.Transformations.New('DTS.DataPumpTransformCopy');
oTransformation := oTransformationOld as Transformation2;
oTransformation.Name := 'DirectCopyXform';
oTransformation.TransformFlags := 63;
oTransformation.ForceSourceBlobsBuffered := 0;
oTransformation.ForceBlobsInMemory := False;
oTransformation.InMemoryBlobSize := 1048576;
oTransformation.TransformPhases := 4;
oCustomTask2.Transformations.Add(oTransformation);
oTransformation := nil;
oTransformationOld := nil;
end;
var
opackageold : package;
opckage : package;
dts_conn, dts_conn2 : connection; //数据库的连接
dts_task : task;
dts_customtask : customtask;
dts_pumptask : datapumptask2;
dts_step : step;
begin
opackageold := Copackage.Create;
opckage := opackageold as package;
//opckage := Createoleobject('DTS.Package');
dts_conn := opckage.Connections.New('SQLOLEDB');
dts_conn2 := opckage.Connections.New('SQLOLEDB');
dts_conn.Catalog := 'db_pay';
dts_conn.ID := 1;
dts_conn.DataSource := 'bcj';
dts_conn.UserID := 'sa';
dts_conn.Password := '00';
//dts_conn.Reusable := true;
//dts_Conn.UseTrustedConnection := false;
//dts_conn.ConnectImmediate := false;

dts_conn2.Catalog := 'db_pay';
dts_conn2.ID := 2;
dts_conn2.DataSource := 'bcj';
dts_conn2.UserID := 'sa';
dts_conn2.Password := '00';
//dts_conn2.Reusable := true;
//dts_Conn2.UseTrustedConnection := false;
//dts_conn2.ConnectImmediate := false;

opckage.Connections.Add(dts_conn);
opckage.Connections.Add(dts_conn2);

dts_step := opckage.Steps.New;
dts_task := opckage.Tasks.New('DTSdatapumptask');
dts_task.Name := 'copy table';
dts_customtask := dts_task.CustomTask;

dts_pumptask := dts_customtask as datapumptask2;
dts_pumptask.Name := 'copy table';

dts_pumptask.SourceConnectionID := 1;
//dts_pumptask.sourceObjectName := 'TCardSoucesdfsdf';
dts_pumptask.SourceSQLStatement := 'select top 100 * from TCardSource';

dts_pumptask.DestinationConnectionID := 2;

dts_pumptask.DestinationObjectName := 'TCardData';
//dts_pumptask.DestinationSQLStatement := 'select * from TCardData';

dts_step.Name := 'LowerCaseStep';
dts_step.TaskName := dts_pumptask.Name;

dts_step.ExecuteInMainThread := true;
dts_pumptask.ProgressRowCount := 100;
dts_pumptask.MaximumErrorCount := 0;
dts_pumptask.FetchBufferSize := 1;
dts_pumptask.UseFastLoad := true;
dts_pumptask.InsertCommitSize := 0;

dts_pumptask.ExceptionFileColumnDelimiter := '|';
dts_pumptask.ExceptionFileRowDelimiter := #13#10;

dts_pumptask.AllowIdentityInserts := false;
dts_pumptask.FirstRow := 0;
dts_pumptask.LastRow := 0;
dts_pumptask.FastLoadOptions := 2;
oCustomTask2_Trans_S1(dts_pumptask);
opckage.Tasks.Add(dts_task);
opckage.Steps.Add(dts_step);
opckage.Execute;

opckage.UnInitialize;

end;
执行后没有任何反应。请高手看看呀!
 
procedure TFrmMain.BitBtn3Click(Sender: TObject);
procedure oCustomTask2_Trans_S1(oCustomTask2: DataPumpTask2);
var
oTransformationOld: Transformation;
oTransformation: Transformation2;
begin
oTransformationOld := oCustomTask2.Transformations.New('DTS.DataPumpTransformCopy');
oTransformation := oTransformationOld as Transformation2;
oTransformation.Name := 'DirectCopyXform';
oTransformation.TransformFlags := 63;
oTransformation.ForceSourceBlobsBuffered := 0;
oTransformation.ForceBlobsInMemory := False;
oTransformation.InMemoryBlobSize := 1048576;
oTransformation.TransformPhases := 4;
oCustomTask2.Transformations.Add(oTransformation);
oTransformation := nil;
oTransformationOld := nil;
end;
var
opackageold : package;
opckage : package;
dts_conn, dts_conn2 : connection; //数据库的连接
dts_task : task;
dts_customtask : customtask;
dts_pumptask : datapumptask2;
dts_step : step;
begin
opackageold := Copackage.Create;
opckage := opackageold as package;
//opckage := Createoleobject('DTS.Package');
dts_conn := opckage.Connections.New('SQLOLEDB');
dts_conn2 := opckage.Connections.New('SQLOLEDB');
dts_conn.Catalog := 'db_pay';
dts_conn.ID := 1;
dts_conn.DataSource := 'bcj';
dts_conn.UserID := 'sa';
dts_conn.Password := '00';
//dts_conn.Reusable := true;
//dts_Conn.UseTrustedConnection := false;
//dts_conn.ConnectImmediate := false;

dts_conn2.Catalog := 'db_pay';
dts_conn2.ID := 2;
dts_conn2.DataSource := 'bcj';
dts_conn2.UserID := 'sa';
dts_conn2.Password := '00';
//dts_conn2.Reusable := true;
//dts_Conn2.UseTrustedConnection := false;
//dts_conn2.ConnectImmediate := false;

opckage.Connections.Add(dts_conn);
opckage.Connections.Add(dts_conn2);

dts_step := opckage.Steps.New;
dts_task := opckage.Tasks.New('DTSdatapumptask');
dts_task.Name := 'copy table';
dts_customtask := dts_task.CustomTask;

dts_pumptask := dts_customtask as datapumptask2;
dts_pumptask.Name := 'copy table';

dts_pumptask.SourceConnectionID := 1;
//dts_pumptask.sourceObjectName := 'TCardSoucesdfsdf';
dts_pumptask.SourceSQLStatement := 'select top 100 * from TCardSource';

dts_pumptask.DestinationConnectionID := 2;

dts_pumptask.DestinationObjectName := 'TCardData';
//dts_pumptask.DestinationSQLStatement := 'select * from TCardData';

dts_step.Name := 'LowerCaseStep';
dts_step.TaskName := dts_pumptask.Name;

dts_step.ExecuteInMainThread := true;
dts_pumptask.ProgressRowCount := 100;
dts_pumptask.MaximumErrorCount := 0;
dts_pumptask.FetchBufferSize := 1;
dts_pumptask.UseFastLoad := true;
dts_pumptask.InsertCommitSize := 0;

dts_pumptask.ExceptionFileColumnDelimiter := '|';
dts_pumptask.ExceptionFileRowDelimiter := #13#10;

dts_pumptask.AllowIdentityInserts := false;
dts_pumptask.FirstRow := 0;
dts_pumptask.LastRow := 0;
dts_pumptask.FastLoadOptions := 2;
oCustomTask2_Trans_S1(dts_pumptask);
opckage.Tasks.Add(dts_task);
opckage.Steps.Add(dts_step);
opckage.Execute;

opckage.UnInitialize;

end;
执行后没有任何反应。请高手看看呀!
 
高手都哪去了呀!
 
原因是你没有在目标数据库上创建表TCardData,这个表与源表要有一样的结构,
如果结果不一样,就得在oCustomTask2_Trans_S1里写目标列与源列的对应关系
 
还有就是DTS导入没有进度条,但sqlserver做的dts数据导入导出有进度条,你想有进度条也做得到,只是有通过另外的工具生成一个控件,这个控件可以有进度显示.
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,DTS_TLB, DTSPump_TLB;

type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.btn1Click(Sender: TObject);
procedure oCustomTask2_Trans_S1(oCustomTask2: DataPumpTask2);
var
oTransformationOld: Transformation;
oTransformation: Transformation2;
begin
oTransformationOld := oCustomTask2.Transformations.New('DTS.DataPumpTransformCopy');
oTransformation := oTransformationOld as Transformation2;
oTransformation.Name := 'DirectCopyXform';
oTransformation.TransformFlags := 63;
oTransformation.ForceSourceBlobsBuffered := 0;
oTransformation.ForceBlobsInMemory := False;
oTransformation.InMemoryBlobSize := 1048576;
oTransformation.TransformPhases := 4;
oCustomTask2.Transformations.Add(oTransformation);
oTransformation := nil;
oTransformationOld := nil;
end;
procedure tracePackageError(oPackage: Package);
var
ErrorCode: integer;
ErrorSource: wideString;
ErrorDescription: wideString;
ErrorHelpFile: wideString;
ErrorHelpContext: integer;
ErrorIDofInterfaceWithError: wideString;
i: Integer;
begin
for i := 1 to oPackage.Steps.Count do
if oPackage.Steps.Item(i).ExecutionResult = DTSStepExecResult_Failure then
begin
oPackage.Steps.Item(i).GetExecutionErrorInfo(ErrorCode, ErrorSource,
ErrorDescription,
ErrorHelpFile, ErrorHelpContext, ErrorIDofInterfaceWithError);
MessageBox(0,pchar(string(oPackage.Steps.item(i).Name) + ' 失败 ' + #10#13 + string(ErrorSource
)+ #10#13 + string(ErrorDescription)),'错误', MB_OK+MB_ICONERROR ); //弹出错误对话
end;

end;
var
opackageold : package;
opckage : package;
dts_conn, dts_conn2 : connection; //数据库的连接
dts_task : task;
dts_customtask : customtask;
dts_pumptask : datapumptask2;
dts_step : step;
begin
opackageold := Copackage.Create;
opckage := opackageold as package;
//opckage := Createoleobject('DTS.Package');
dts_conn := opckage.Connections.New('SQLOLEDB');
dts_conn2 := opckage.Connections.New('SQLOLEDB');
dts_conn.Catalog := 'test';
dts_conn.ID := 1;
dts_conn.DataSource := '(local)';
dts_conn.UserID := 'sa';
dts_conn.Password := 'csb';
//dts_conn.Reusable := true;
//dts_Conn.UseTrustedConnection := false;
//dts_conn.ConnectImmediate := false;

dts_conn2.Catalog := 'test';
dts_conn2.ID := 2;
dts_conn2.DataSource := '(local)';
dts_conn2.UserID := 'sa';
dts_conn2.Password := 'csb';
//dts_conn2.Reusable := true;
//dts_Conn2.UseTrustedConnection := false;
//dts_conn2.ConnectImmediate := false;

opckage.Connections.Add(dts_conn);
opckage.Connections.Add(dts_conn2);

dts_step := opckage.Steps.New;
dts_task := opckage.Tasks.New('DTSdatapumptask');
dts_task.Name := 'copy table';
dts_customtask := dts_task.CustomTask;

dts_pumptask := dts_customtask as datapumptask2;
dts_pumptask.Name := 'copy table';

dts_pumptask.SourceConnectionID := 1;
//dts_pumptask.sourceObjectName := 'TCardSoucesdfsdf';
dts_pumptask.SourceSQLStatement := 'select top 100 * from TCardSource';

dts_pumptask.DestinationConnectionID := 2;

dts_pumptask.DestinationObjectName := 'TCardData';
//dts_pumptask.DestinationSQLStatement := 'select * from TCardData';

dts_step.Name := 'LowerCaseStep';
dts_step.TaskName := dts_pumptask.Name;

dts_step.ExecuteInMainThread := true;
dts_pumptask.ProgressRowCount := 100;
dts_pumptask.MaximumErrorCount := 0;
dts_pumptask.FetchBufferSize := 1;
dts_pumptask.UseFastLoad := true;
dts_pumptask.InsertCommitSize := 0;

dts_pumptask.ExceptionFileColumnDelimiter := '|';
dts_pumptask.ExceptionFileRowDelimiter := #13#10;

dts_pumptask.AllowIdentityInserts := false;
dts_pumptask.FirstRow := 0;
dts_pumptask.LastRow := 0;
dts_pumptask.FastLoadOptions := 2;
oCustomTask2_Trans_S1(dts_pumptask);
opckage.Tasks.Add(dts_task);
opckage.Steps.Add(dts_step);
opckage.Execute;
tracePackageError(opckage);
opckage.UnInitialize;

end;




end.
 
你到
http://www.techvanguards.com/files/EventSinkImp.msi
下载一个工具生成 dtsEvents.pas文件,注册成控件,然后在新控件里进度代码,我用了很爽.
我这里有一个
{ *****************************************************************************
WARNING: This component file was generated using the EventSinkImp utility.
The contents of this file will be overwritten everytime EventSinkImp
is asked to regenerate this sink component.

NOTE: When using this component at the same time with the XXX_TLB.pas in
your Delphi projects, make sure you always put the XXX_TLB unit name
AFTER this component unit name in the USES clause of the interface
section of your unit; otherwise you may get interface conflict
errors from the Delphi compiler.

EventSinkImp is written by Binh Ly (bly@techvanguards.com)
*****************************************************************************
//Sink Classes//
TDTSPackageEvents
}

{$IFDEF VER100}
{$DEFINE D3}
{$ENDIF}

//SinkUnitName//
unit DTSEvents;

interface

uses
Windows, ActiveX, Classes, ComObj, OleCtrls
//SinkUses//
, StdVCL
, DTS_TLB
;

type
{ backward compatibility types }
{$IFDEF D3}
OLE_COLOR = TOleColor;
{$ENDIF}

TDTSEventsBaseSink = class (TComponent, IUnknown, IDispatch)
protected
{ IUnknown }
function QueryInterface(const IID: TGUID; out Obj): HResult; {$IFNDEF D3} override; {$ENDIF} stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;

{ IDispatch }
function GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; virtual; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; virtual; stdcall;
function GetTypeInfoCount(out Count: Integer): HResult; virtual; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; virtual; stdcall;
protected
FCookie: integer;
FCP: IConnectionPoint;
FSinkIID: TGUID;
FSource: IUnknown;
function DoInvoke (DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var dps: TDispParams; pDispIds: PDispIdList;
VarResult, ExcepInfo, ArgErr: Pointer): HResult; virtual; abstract;
public
destructor Destroy; override;
procedure Connect (const ASource: IUnknown);
procedure Disconnect;
property SinkIID: TGUID read FSinkIID write FSinkIID;
property Source: IUnknown read FSource;
end;

//SinkImportsForwards//

//SinkImports//

//SinkIntfStart//

//SinkEventsForwards//
TPackageEventsOnStartEvent = function (Sender: TObject; const EventSource: WideString): HResult of object;
TPackageEventsOnFinishEvent = function (Sender: TObject; const EventSource: WideString): HResult of object;
TPackageEventsOnErrorEvent = function (Sender: TObject; const EventSource: WideString; ErrorCode: Integer; const Source: WideString; const Description: WideString; const HelpFile: WideString; HelpContext: Integer; const IDofInterfaceWithError: WideString; var pbCancel: WordBool): HResult of object;
TPackageEventsOnProgressEvent = function (Sender: TObject; const EventSource: WideString; const ProgressDescription: WideString; PercentComplete: Integer; ProgressCountLow: Integer; ProgressCountHigh: Integer): HResult of object;
TPackageEventsOnQueryCancelEvent = function (Sender: TObject; const EventSource: WideString; var pbCancel: WordBool): HResult of object;

//SinkComponent//
TDTSPackageEvents = class (TDTSEventsBaseSink , PackageEvents)
protected
function DoInvoke (DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var dps: TDispParams; pDispIds: PDispIdList;
VarResult, ExcepInfo, ArgErr: Pointer): HResult; override;

{ PackageEvents }
function PackageEvents.OnStart = DoOnStart;
function PackageEvents.OnFinish = DoOnFinish;
function PackageEvents.OnError = DoOnError;
function PackageEvents.OnProgress = DoOnProgress;
function PackageEvents.OnQueryCancel = DoOnQueryCancel;
public
{ system methods }
constructor Create (AOwner: TComponent); override;
protected
//SinkInterface//
function DoOnStart(const EventSource: WideString): HResult; stdcall;
function DoOnFinish(const EventSource: WideString): HResult; stdcall;
function DoOnError(const EventSource: WideString; ErrorCode: Integer; const Source: WideString; const Description: WideString; const HelpFile: WideString; HelpContext: Integer; const IDofInterfaceWithError: WideString; var pbCancel: WordBool): HResult; stdcall;
function DoOnProgress(const EventSource: WideString; const ProgressDescription: WideString; PercentComplete: Integer; ProgressCountLow: Integer; ProgressCountHigh: Integer): HResult; stdcall;
function DoOnQueryCancel(const EventSource: WideString; var pbCancel: WordBool): HResult; stdcall;
protected
//SinkEventsProtected//
FOnStart: TPackageEventsOnStartEvent;
FOnFinish: TPackageEventsOnFinishEvent;
FOnError: TPackageEventsOnErrorEvent;
FOnProgress: TPackageEventsOnProgressEvent;
FOnQueryCancel: TPackageEventsOnQueryCancelEvent;
published
//SinkEventsPublished//
property OnStart: TPackageEventsOnStartEvent read FOnStart write FOnStart;
property OnFinish: TPackageEventsOnFinishEvent read FOnFinish write FOnFinish;
property OnError: TPackageEventsOnErrorEvent read FOnError write FOnError;
property OnProgress: TPackageEventsOnProgressEvent read FOnProgress write FOnProgress;
property OnQueryCancel: TPackageEventsOnQueryCancelEvent read FOnQueryCancel write FOnQueryCancel;
end;

//SinkIntfEnd//

procedure Register;

implementation

uses
SysUtils;

{ globals }

procedure BuildPositionalDispIds (pDispIds: PDispIdList; const dps: TDispParams);
var
i: integer;
begin
Assert (pDispIds <> nil);

{ by default, directly arrange in reverse order }
for i := 0 to dps.cArgs - 1 do
pDispIds^ := dps.cArgs - 1 - i;

{ check for named args }
if (dps.cNamedArgs <= 0) then Exit;

{ parse named args }
for i := 0 to dps.cNamedArgs - 1 do
pDispIds^ [dps.rgdispidNamedArgs^ ] := i;
end;


{ TDTSEventsBaseSink }

function TDTSEventsBaseSink.GetIDsOfNames(const IID: TGUID; Names: Pointer;
NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
begin
Result := E_NOTIMPL;
end;

function TDTSEventsBaseSink.GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult;
begin
Result := E_NOTIMPL;
pointer (TypeInfo) := nil;
end;

function TDTSEventsBaseSink.GetTypeInfoCount(out Count: Integer): HResult;
begin
Result := E_NOTIMPL;
Count := 0;
end;

function TDTSEventsBaseSink.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
var
dps: TDispParams absolute Params;
bHasParams: boolean;
pDispIds: PDispIdList;
iDispIdsSize: integer;
begin
{ validity checks }
if (Flags AND DISPATCH_METHOD = 0) then
raise Exception.Create (
Format ('%s only supports sinking of method calls!', [ClassName]
));

{ build pDispIds array. this maybe a bit of overhead but it allows us to
sink named-argument calls such as Excel's AppEvents, etc!
}
pDispIds := nil;
iDispIdsSize := 0;
bHasParams := (dps.cArgs > 0);
if (bHasParams) then
begin
iDispIdsSize := dps.cArgs * SizeOf (TDispId);
GetMem (pDispIds, iDispIdsSize);
end; { if }

try
{ rearrange dispids properly }
if (bHasParams) then BuildPositionalDispIds (pDispIds, dps);
Result := DoInvoke (DispId, IID, LocaleID, Flags, dps, pDispIds, VarResult, ExcepInfo, ArgErr);
finally
{ free pDispIds array }
if (bHasParams) then FreeMem (pDispIds, iDispIdsSize);
end; { finally }
end;

function TDTSEventsBaseSink.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
if (GetInterface (IID, Obj)) then
begin
Result := S_OK;
Exit;
end
else
if (IsEqualIID (IID, FSinkIID)) then
if (GetInterface (IDispatch, Obj)) then
begin
Result := S_OK;
Exit;
end;
Result := E_NOINTERFACE;
pointer (Obj) := nil;
end;

function TDTSEventsBaseSink._AddRef: Integer;
begin
Result := 2;
end;

function TDTSEventsBaseSink._Release: Integer;
begin
Result := 1;
end;

destructor TDTSEventsBaseSink.Destroy;
begin
Disconnect;
inherited;
end;

procedure TDTSEventsBaseSink.Connect (const ASource: IUnknown);
var
pcpc: IConnectionPointContainer;
begin
Assert (ASource <> nil);
Disconnect;
try
OleCheck (ASource.QueryInterface (IConnectionPointContainer, pcpc));
OleCheck (pcpc.FindConnectionPoint (FSinkIID, FCP));
OleCheck (FCP.Advise (Self, FCookie));
FSource := ASource;
except
raise Exception.Create (Format ('Unable to connect %s.'#13'%s',
[Name, Exception (ExceptObject).Message]
));
end; { finally }
end;

procedure TDTSEventsBaseSink.Disconnect;
begin
if (FSource = nil) then Exit;
try
OleCheck (FCP.Unadvise (FCookie));
FCP := nil;
FSource := nil;
except
pointer (FCP) := nil;
pointer (FSource) := nil;
end; { except }
end;


//SinkImplStart//

function TDTSPackageEvents.DoInvoke (DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var dps: TDispParams; pDispIds: PDispIdList;
VarResult, ExcepInfo, ArgErr: Pointer): HResult;
type
POleVariant = ^OleVariant;
begin
Result := DISP_E_MEMBERNOTFOUND;

//SinkInvoke//
//SinkInvokeEnd//
end;

constructor TDTSPackageEvents.Create (AOwner: TComponent);
begin
inherited Create (AOwner);
//SinkInit//
FSinkIID := PackageEvents;
end;

//SinkImplementation//
function TDTSPackageEvents.DoOnStart(const EventSource: WideString): HResult;
begin
Result := S_OK;
if not Assigned (OnStart) then System.Exit;
Result := OnStart (Self, EventSource);
end;

function TDTSPackageEvents.DoOnFinish(const EventSource: WideString): HResult;
begin
Result := S_OK;
if not Assigned (OnFinish) then System.Exit;
Result := OnFinish (Self, EventSource);
end;

function TDTSPackageEvents.DoOnError(const EventSource: WideString; ErrorCode: Integer; const Source: WideString; const Description: WideString; const HelpFile: WideString; HelpContext: Integer; const IDofInterfaceWithError: WideString; var pbCancel: WordBool): HResult;
begin
Result := S_OK;
if not Assigned (OnError) then System.Exit;
Result := OnError (Self, EventSource, ErrorCode, Source, Description, HelpFile, HelpContext, IDofInterfaceWithError, pbCancel);
end;

function TDTSPackageEvents.DoOnProgress(const EventSource: WideString; const ProgressDescription: WideString; PercentComplete: Integer; ProgressCountLow: Integer; ProgressCountHigh: Integer): HResult;
begin
Result := S_OK;
if not Assigned (OnProgress) then System.Exit;
Result := OnProgress (Self, EventSource, ProgressDescription, PercentComplete, ProgressCountLow, ProgressCountHigh);
end;

function TDTSPackageEvents.DoOnQueryCancel(const EventSource: WideString; var pbCancel: WordBool): HResult;
begin
Result := S_OK;
if not Assigned (OnQueryCancel) then System.Exit;
Result := OnQueryCancel (Self, EventSource, pbCancel);
end;


//SinkImplEnd//

procedure Register;
begin
//SinkRegisterStart//
RegisterComponents ('ActiveX', [TDTSPackageEvents]);
//SinkRegisterEnd//
end;

end.
 
新控件与Dts连接的方法如下
DTSPackageEvents1.Connect(oPackage);

dts复制数据所需的dll文件
dtspkg.dll
dtspkg.rll
dtspump.dll
dtspump.rll
sqlresld.dll
 
楼上的高手兄弟可以加我吗?
MSN:bcj1983@hotmail.com
QQ :27857491
另注TCardData表数据库中已经存在,不能创建的。
 
那你只能用指定目标列和指定源列的对应关系了.
 
我加你QQ时:服务器拒绝您的请求,出错原因:对不起,请稍候再试
我的QQ:10772221
验证请输入,dts
 
procedure TFrmMain.Button1Click(Sender: TObject);
procedure tracePackageError(oPackage: olevariant);
var
ErrorCode: integer;
ErrorSource: wideString;
ErrorDescription: wideString;
ErrorHelpFile: wideString;
ErrorHelpContext: integer;
ErrorIDofInterfaceWithError: wideString;
i: Integer;
begin
for i := 1 to oPackage.Steps.Count do
if oPackage.Steps.Item(i).ExecutionResult = DTSStepExecResult_Failure then
begin
oPackage.Steps.Item(i).GetExecutionErrorInfo(ErrorCode, ErrorSource,
ErrorDescription,
ErrorHelpFile, ErrorHelpContext, ErrorIDofInterfaceWithError);
MessageBox(0,pchar(string(oPackage.Steps.item(i).Name) + ' 失败 ' + #10#13 + string(ErrorSource
)+ #10#13 + string(ErrorDescription)),'错误', MB_OK+MB_ICONERROR ); //弹出错误对话
end;

end;
var
oPackage : olevariant;
oTask,
oCustomTask : olevariant;
oStep : olevariant;
begin
oPackage:=Createoleobject('DTS.Package');
oPackage.LoadFromSQLServer('bcj','sa','00',dts_tlb.DTSSQLStgFlag_Default,'','','','test');
oTask := opackage.Tasks.item(1);
//oTask := oPackage.Tasks.New('DTSdatapumptask');
oCustomTask:=oTask.CustomTask;

oStep := opackage.Steps.Item(1);

oCustomTask.SourceSQLStatement:='select top 10 * from dbuser_pay.TCardData';
//opackage.Tasks.Add(oTask);
oStep.TaskName:=oCustomTask.Name;

showmessage(oCustomTask.name);
opackage.Execute;
tracePackageError(oPackage);
//oCustomTask := oTask.CustomTask;
end;

在来看下这段代码。我获取了服务器上的 task 与 step 接口。然后改变其参数再执行,也没有反应呀!
 
兄弟我搞定了。妈的!两次错误都是我的原因。第一个没加表所有者,因为哪个表不是
SA创建的。第二个是源表是个空表,我还以为有数据呢!我说怎么导不过去呢!
害了我搞了二天。
感谢 chenshaizi 兄弟。
请楼主将分给予 chenshaizi 兄弟
 
后退
顶部