SQL Server 2000中的DTS服务编程(回答正确再加200)(100分)

  • 主题发起人 主题发起人 spear
  • 开始时间 开始时间
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;
 
看样子是没有人能回答了?
 
EXCEPTION_ACCESS_VIOLATION'
这个错误一般是由于访问了空对象,不存在的对象,已释放的对象等
原因产生的。
好好看看自己的代码吧,看看有没有没有建立就使用的对象等
贴子太长了,实在懒得看,自己认真检查一下应该可以解决的:)
祝:
好运
 
看样子是没有人能解决了,换个问题吧。
我把TStringGrid的DefaultDrawing置为false,
并写了OnDrawCell事件,但在循环中使用以下程序代码时
with StrGrid do begin
Cells[0, RowCount-1] := IntToStr(RowCount-1);
Cells[1, RowCount-1] := Cell1;
Cells[2, RowCount-1] := Cell2;
Cells[3, RowCount-1] := Cell3;
Cells[4, RowCount-1] := Cell4;
RowCount := RowCount + 1;
if RowCount >= VisibleRowCount then
TopRow := RowCount - VisibleRowCount;
end;
会引起StrGrid在每次循环时都会从第一行重画到最后一行,而我的程序只需要重画
TopRow到最后一行即可。
 
应该不会有空指针,因为我是先把sql server的DTS包存为vb程序,再改写delphi程序的.
另外我在www.sqlmag.com中查到过,可能是因为delphi的线程模型和dts的线程模型不一
致导致的,可这句话我自己也不明白.所以现在只好放弃在程序使用dts包了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部