S
spear
Unregistered / Unconfirmed
GUEST, unregistred user!
首先用Import Type Library将dtspkg.dll与dtspump.dll导入,再使用以下程序,
会出现错误信息: raised exception class EOleException with message '提供
程序生成的代码招待异常错误:EXCEPTION_ACCESS_VIOLATION'
procedure TFrmDts.SetupPackage(oPkg2: Package2);
begin
oPkg2.Name := 'test';
oPkg2.WriteCompletionStatusToNTEventLog := true;
oPkg2.LogFileName := 'd:/query/dts/error.txt';
oPkg2.FailOnError := false;
oPkg2.PackagePriorityClass := 2;
oPkg2.MaxConcurrentSteps := 4;
oPkg2.LineageOptions := 0;
oPkg2.UseTransaction := true;
oPkg2.TransactionIsolationLevel := 4096;
oPkg2.AutoCommitTransaction := true;
oPkg2.RepositoryMetadataOptions := 0;
oPkg2.UseOLEDBServiceComponents := true;
oPkg2.LogToSQLServer := false;
oPkg2.LogServerFlags := 0;
oPkg2.FailPackageOnLogFailure := false;
oPkg2.ExplicitGlobalVariables := false;
oPkg2.PackageType := 0;
end;
procedure TFrmDts.CreateConns(oPkg2: Package2);
var
oConn: Connection2;
begin
oConn := oPkg2.Connections.New('MSDASQL') as Connection2;
oConn.ConnectionProperties.Item('Persist Security Info').Value := true;
oConn.ConnectionProperties.Item('User ID').Value := 'xzy';
oConn.ConnectionProperties.Item('Data Source').Value := 'bankdta';
oConn.Name := 'bank';
oConn.ID := 1;
oConn.Reusable := true;
oConn.DataSource := 'bankdta';
oConn.UserID := 'xzy';
oConn.Password := 'xzy';
oConn.ConnectionTimeout := 60;
oConn.UseTrustedConnection := false;
oConn.UseDSL := false;
oPkg2.Connections.Add(oConn as Connection);
oConn := nil;
oConn := oPkg2.Connections.New('SQLOLEDB') as Connection2;
oConn.ConnectionProperties.Item('Integrated Security').Value := 'SSPI';
oConn.ConnectionProperties.Item('Persist Security Info').Value := true;
oConn.ConnectionProperties.Item('Initial Catalog').Value := 'rpt';
oConn.ConnectionProperties.Item('Data Source').Value := 'RPT-SERVER';
oConn.ConnectionProperties.Item('Application Name').Value := 'manual design';
oConn.Name := 'rpt';
oConn.ID := 2;
oConn.Reusable := true;
oConn.ConnectImmediate := false;
oConn.DataSource := 'RPT-SERVER';
oConn.ConnectionTimeout := 60;
oConn.Catalog := 'rpt';
oConn.UserID := 'xzy';
oConn.Password := 'x1111';
oConn.UseTrustedConnection := true;
oConn.UseDSL := false;
oPkg2.Connections.Add(oConn as Connection);
oConn := nil;
end;
procedure TFrmDts.CreateSteps(oPkg2: Package2; i: Integer);
var
si: String;
oStep: Step2;
oConstraint: PrecedenceConstraint;
begin
si := IntToStr(i);
oStep := oPkg2.Steps.New as Step2;
oStep.Name := 'step_execsql_' + si;
oStep.ExecutionStatus := 1;
oStep.TaskName := 'task_execsql_' + si;
oStep.CommitSuccess := false;
oStep.RollbackFailure := false;
oStep.ScriptLanguage := 'VBScript';
oStep.AddGlobalVariables := true;
oStep.RelativePriority := 3;
oStep.CloseConnection := false;
oStep.ExecuteInMainThread := true;
oStep.IsPackageDSORowset := false;
oStep.DisableStep := false;
// oStep.FailPackageOnError := false;
oPkg2.Steps.Add(oStep);
oStep := nil;
oStep := oPkg2.Steps.New as Step2;
oStep.Name := 'step_datapump_' + si;
oStep.TaskName := 'task_datapump' + si;
oStep.ExecutionStatus := 1;
oStep.CommitSuccess := false;
oStep.RollbackFailure := false;
oStep.ScriptLanguage := 'VBScript';
oStep.AddGlobalVariables := true;
oStep.RelativePriority := 3;
oStep.CloseConnection := false;
oStep.ExecuteInMainThread := true;
oStep.IsPackageDSORowset := false;
oStep.DisableStep := false;
// oStep.FailPackageOnError := false;
oPkg2.Steps.Add(oStep);
oStep := nil;
oStep := oPkg2.Steps.Item('step_datapump_' + si) as Step2;
oConstraint := oStep.PrecedenceConstraints.New('step_execsql_' + si);
oConstraint.StepName := 'step_execsql_' + si;
oConstraint.PrecedenceBasis := 0;
oConstraint.Value := 4;
oStep.PrecedenceConstraints.Add(oConstraint);
oConstraint := nil;
end;
procedure TFrmDts.ExecSQLTask(oPkg2: Package2; i: Integer);
var
oTask: Task;
oCustomTask: ExecuteSQLTask2;
begin
oTask := oPkg2.Tasks.New('DTSExecuteSQLTask');
oCustomTask := oTask.CustomTask as ExecuteSQLTask2 ;
oCustomTask.Name := 'task_execsql_' + IntToStr(i);
oCustomTask.SQLStatement := 'truncate table brm';
oCustomTask.ConnectionID := 2;
oCustomTask.CommandTimeout := 0;
oCustomTask.OutputAsRecordset := false;
oPkg2.Tasks.Add(oTask);
oCustomTask := nil;
oTask := nil;
end;
procedure TFrmDts.ExecPumpTask(oPkg2: Package2; i: Integer);
var
oTask: Task;
oCustomTask: DataPumpTask2;
procedure Trans(oTask1: DataPumpTask);
var
oTrans: Transformation2;
oCol: Column;
begin
oTrans := oTask1.Transformations.New('DTSPump.DataPumpTransformCopy') as Transformation2;
oTrans.Name := 'trans' + IntToStr(i);
oTrans.TransformFlags := 63;
oTrans.ForceSourceBlobsBuffered := 0;
oTrans.ForceBlobsInMemory := false;
oTrans.InMemoryBlobSize := 1048576;
oTrans.TransformPhases := 4;
oCol := oTrans.SourceColumns.New('BRRL', 1);
oCol.Name := 'BRRL';
oCol.Ordinal := 1;
oCol.Flags := 20;
oCol.Size := 0;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.SourceColumns.Add(oCol);
oCol := nil;
oCol := oTrans.SourceColumns.New('BRNM', 2);
oCol.Name := 'BRNM';
oCol.Ordinal := 2;
oCol.Flags := 20;
oCol.Size := 0;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.SourceColumns.Add(oCol);
oCol := nil;
oCol := oTrans.SourceColumns.New('BRNO', 3);
oCol.Name := 'BRNO';
oCol.Ordinal := 3;
oCol.Flags := 20;
oCol.Size := 0;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.SourceColumns.Add(oCol);
oCol := nil;
oCol := oTrans.DestinationColumns.New('BRRL', 1);
oCol.Name := 'BRRL';
oCol.Ordinal := 1;
oCol.Flags := 24;
oCol.Size := 4;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.DestinationColumns.Add(oCol);
oCol := nil;
oCol := oTrans.DestinationColumns.New('BRNM', 2);
oCol.Name := 'BRNM';
oCol.Ordinal := 2;
oCol.Flags := 24;
oCol.Size := 50;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.DestinationColumns.Add(oCol);
oCol := nil;
oCol := oTrans.DestinationColumns.New('BRNO', 3);
oCol.Name := 'BRNO';
oCol.Ordinal := 3;
oCol.Flags := 24;
oCol.Size := 4;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.DestinationColumns.Add(oCol);
oCol := nil;
oTask1.Transformations.Add(oTrans);
oTrans := nil;
end;
begin
oTask := oPkg2.Tasks.New('DTSDataPumpTask');
oCustomTask := oTask.CustomTask as DataPumpTask2;
oCustomTask.Name := 'task_datapump_' + IntToStr(i);
oCustomTask.SourceConnectionID := 1;
oCustomTask.SourceObjectName := 'BRM';
oCustomTask.DestinationConnectionID := 2;
oCustomTask.DestinationObjectName := 'BRM';
oCustomTask.ProgressRowCount := 50;
oCustomTask.MaximumErrorCount := 0;
oCustomTask.ExceptionFileName := 'd:/query/dts/exception.txt';
oCustomTask.FetchBufferSize := 1;
oCustomTask.UseFastLoad := true;
oCustomTask.InsertCommitSize := 0;
oCustomTask.ExceptionFileColumnDelimiter := '|';
oCustomTask.ExceptionFileRowDelimiter := #13#10;
oCustomTask.AllowIdentityInserts := false;
oCustomTask.FirstRow := 0;
oCustomTask.LastRow := 0;
oCustomTask.FastLoadOptions := 2;
oCustomTask.ExceptionFileOptions := 1;
oCustomTask.DataPumpOptions := 0;
Trans(oCustomTask);
oPkg2.Tasks.Add(oTask);
oCustomTask := nil;
oTask := nil;
end;
procedure TFrmDts.BtnQuitClick(Sender: TObject);
begin
Close;
end;
procedure TFrmDts.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to Lv1.Items.Count - 1 do
Lv1.Items.Checked := false;
end;
procedure TFrmDts.Button2Click(Sender: TObject);
var
oPkg2: _Package2;
begin
oPkg2 := Package.DefaultInterface as Package2;
SetupPackage(oPkg2);
CreateConns(oPkg2);
CreateSteps(oPkg2, 1);
ExecSQLTask(oPkg2, 1);
ExecPumpTask(oPkg2, 1);
oPkg2.Execute;
oPkg2.UnInitialize;
end;
会出现错误信息: raised exception class EOleException with message '提供
程序生成的代码招待异常错误:EXCEPTION_ACCESS_VIOLATION'
procedure TFrmDts.SetupPackage(oPkg2: Package2);
begin
oPkg2.Name := 'test';
oPkg2.WriteCompletionStatusToNTEventLog := true;
oPkg2.LogFileName := 'd:/query/dts/error.txt';
oPkg2.FailOnError := false;
oPkg2.PackagePriorityClass := 2;
oPkg2.MaxConcurrentSteps := 4;
oPkg2.LineageOptions := 0;
oPkg2.UseTransaction := true;
oPkg2.TransactionIsolationLevel := 4096;
oPkg2.AutoCommitTransaction := true;
oPkg2.RepositoryMetadataOptions := 0;
oPkg2.UseOLEDBServiceComponents := true;
oPkg2.LogToSQLServer := false;
oPkg2.LogServerFlags := 0;
oPkg2.FailPackageOnLogFailure := false;
oPkg2.ExplicitGlobalVariables := false;
oPkg2.PackageType := 0;
end;
procedure TFrmDts.CreateConns(oPkg2: Package2);
var
oConn: Connection2;
begin
oConn := oPkg2.Connections.New('MSDASQL') as Connection2;
oConn.ConnectionProperties.Item('Persist Security Info').Value := true;
oConn.ConnectionProperties.Item('User ID').Value := 'xzy';
oConn.ConnectionProperties.Item('Data Source').Value := 'bankdta';
oConn.Name := 'bank';
oConn.ID := 1;
oConn.Reusable := true;
oConn.DataSource := 'bankdta';
oConn.UserID := 'xzy';
oConn.Password := 'xzy';
oConn.ConnectionTimeout := 60;
oConn.UseTrustedConnection := false;
oConn.UseDSL := false;
oPkg2.Connections.Add(oConn as Connection);
oConn := nil;
oConn := oPkg2.Connections.New('SQLOLEDB') as Connection2;
oConn.ConnectionProperties.Item('Integrated Security').Value := 'SSPI';
oConn.ConnectionProperties.Item('Persist Security Info').Value := true;
oConn.ConnectionProperties.Item('Initial Catalog').Value := 'rpt';
oConn.ConnectionProperties.Item('Data Source').Value := 'RPT-SERVER';
oConn.ConnectionProperties.Item('Application Name').Value := 'manual design';
oConn.Name := 'rpt';
oConn.ID := 2;
oConn.Reusable := true;
oConn.ConnectImmediate := false;
oConn.DataSource := 'RPT-SERVER';
oConn.ConnectionTimeout := 60;
oConn.Catalog := 'rpt';
oConn.UserID := 'xzy';
oConn.Password := 'x1111';
oConn.UseTrustedConnection := true;
oConn.UseDSL := false;
oPkg2.Connections.Add(oConn as Connection);
oConn := nil;
end;
procedure TFrmDts.CreateSteps(oPkg2: Package2; i: Integer);
var
si: String;
oStep: Step2;
oConstraint: PrecedenceConstraint;
begin
si := IntToStr(i);
oStep := oPkg2.Steps.New as Step2;
oStep.Name := 'step_execsql_' + si;
oStep.ExecutionStatus := 1;
oStep.TaskName := 'task_execsql_' + si;
oStep.CommitSuccess := false;
oStep.RollbackFailure := false;
oStep.ScriptLanguage := 'VBScript';
oStep.AddGlobalVariables := true;
oStep.RelativePriority := 3;
oStep.CloseConnection := false;
oStep.ExecuteInMainThread := true;
oStep.IsPackageDSORowset := false;
oStep.DisableStep := false;
// oStep.FailPackageOnError := false;
oPkg2.Steps.Add(oStep);
oStep := nil;
oStep := oPkg2.Steps.New as Step2;
oStep.Name := 'step_datapump_' + si;
oStep.TaskName := 'task_datapump' + si;
oStep.ExecutionStatus := 1;
oStep.CommitSuccess := false;
oStep.RollbackFailure := false;
oStep.ScriptLanguage := 'VBScript';
oStep.AddGlobalVariables := true;
oStep.RelativePriority := 3;
oStep.CloseConnection := false;
oStep.ExecuteInMainThread := true;
oStep.IsPackageDSORowset := false;
oStep.DisableStep := false;
// oStep.FailPackageOnError := false;
oPkg2.Steps.Add(oStep);
oStep := nil;
oStep := oPkg2.Steps.Item('step_datapump_' + si) as Step2;
oConstraint := oStep.PrecedenceConstraints.New('step_execsql_' + si);
oConstraint.StepName := 'step_execsql_' + si;
oConstraint.PrecedenceBasis := 0;
oConstraint.Value := 4;
oStep.PrecedenceConstraints.Add(oConstraint);
oConstraint := nil;
end;
procedure TFrmDts.ExecSQLTask(oPkg2: Package2; i: Integer);
var
oTask: Task;
oCustomTask: ExecuteSQLTask2;
begin
oTask := oPkg2.Tasks.New('DTSExecuteSQLTask');
oCustomTask := oTask.CustomTask as ExecuteSQLTask2 ;
oCustomTask.Name := 'task_execsql_' + IntToStr(i);
oCustomTask.SQLStatement := 'truncate table brm';
oCustomTask.ConnectionID := 2;
oCustomTask.CommandTimeout := 0;
oCustomTask.OutputAsRecordset := false;
oPkg2.Tasks.Add(oTask);
oCustomTask := nil;
oTask := nil;
end;
procedure TFrmDts.ExecPumpTask(oPkg2: Package2; i: Integer);
var
oTask: Task;
oCustomTask: DataPumpTask2;
procedure Trans(oTask1: DataPumpTask);
var
oTrans: Transformation2;
oCol: Column;
begin
oTrans := oTask1.Transformations.New('DTSPump.DataPumpTransformCopy') as Transformation2;
oTrans.Name := 'trans' + IntToStr(i);
oTrans.TransformFlags := 63;
oTrans.ForceSourceBlobsBuffered := 0;
oTrans.ForceBlobsInMemory := false;
oTrans.InMemoryBlobSize := 1048576;
oTrans.TransformPhases := 4;
oCol := oTrans.SourceColumns.New('BRRL', 1);
oCol.Name := 'BRRL';
oCol.Ordinal := 1;
oCol.Flags := 20;
oCol.Size := 0;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.SourceColumns.Add(oCol);
oCol := nil;
oCol := oTrans.SourceColumns.New('BRNM', 2);
oCol.Name := 'BRNM';
oCol.Ordinal := 2;
oCol.Flags := 20;
oCol.Size := 0;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.SourceColumns.Add(oCol);
oCol := nil;
oCol := oTrans.SourceColumns.New('BRNO', 3);
oCol.Name := 'BRNO';
oCol.Ordinal := 3;
oCol.Flags := 20;
oCol.Size := 0;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.SourceColumns.Add(oCol);
oCol := nil;
oCol := oTrans.DestinationColumns.New('BRRL', 1);
oCol.Name := 'BRRL';
oCol.Ordinal := 1;
oCol.Flags := 24;
oCol.Size := 4;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.DestinationColumns.Add(oCol);
oCol := nil;
oCol := oTrans.DestinationColumns.New('BRNM', 2);
oCol.Name := 'BRNM';
oCol.Ordinal := 2;
oCol.Flags := 24;
oCol.Size := 50;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.DestinationColumns.Add(oCol);
oCol := nil;
oCol := oTrans.DestinationColumns.New('BRNO', 3);
oCol.Name := 'BRNO';
oCol.Ordinal := 3;
oCol.Flags := 24;
oCol.Size := 4;
oCol.DataType := 129;
oCol.Precision := 0;
oCol.NumericScale := 0;
oCol.Nullable := false;
oTrans.DestinationColumns.Add(oCol);
oCol := nil;
oTask1.Transformations.Add(oTrans);
oTrans := nil;
end;
begin
oTask := oPkg2.Tasks.New('DTSDataPumpTask');
oCustomTask := oTask.CustomTask as DataPumpTask2;
oCustomTask.Name := 'task_datapump_' + IntToStr(i);
oCustomTask.SourceConnectionID := 1;
oCustomTask.SourceObjectName := 'BRM';
oCustomTask.DestinationConnectionID := 2;
oCustomTask.DestinationObjectName := 'BRM';
oCustomTask.ProgressRowCount := 50;
oCustomTask.MaximumErrorCount := 0;
oCustomTask.ExceptionFileName := 'd:/query/dts/exception.txt';
oCustomTask.FetchBufferSize := 1;
oCustomTask.UseFastLoad := true;
oCustomTask.InsertCommitSize := 0;
oCustomTask.ExceptionFileColumnDelimiter := '|';
oCustomTask.ExceptionFileRowDelimiter := #13#10;
oCustomTask.AllowIdentityInserts := false;
oCustomTask.FirstRow := 0;
oCustomTask.LastRow := 0;
oCustomTask.FastLoadOptions := 2;
oCustomTask.ExceptionFileOptions := 1;
oCustomTask.DataPumpOptions := 0;
Trans(oCustomTask);
oPkg2.Tasks.Add(oTask);
oCustomTask := nil;
oTask := nil;
end;
procedure TFrmDts.BtnQuitClick(Sender: TObject);
begin
Close;
end;
procedure TFrmDts.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i := 0 to Lv1.Items.Count - 1 do
Lv1.Items.Checked := false;
end;
procedure TFrmDts.Button2Click(Sender: TObject);
var
oPkg2: _Package2;
begin
oPkg2 := Package.DefaultInterface as Package2;
SetupPackage(oPkg2);
CreateConns(oPkg2);
CreateSteps(oPkg2, 1);
ExecSQLTask(oPkg2, 1);
ExecPumpTask(oPkg2, 1);
oPkg2.Execute;
oPkg2.UnInitialize;
end;