L
lichaogang
Unregistered / Unconfirmed
GUEST, unregistred user!
1.中间层用了链接数据库来操作不同的数据库
2.中间层组件的事务模式使用了"需要事务"
3.在同一方法中执行链接数据库上的存储过程没有问题但若执行查询(查询链接数据库的表---分布式查询)则会出上述错误
附代码如下:
procedure TPCR_Save.GenSC(BuyerID, SeasonID, ProgID: Integer;
const UserName: WideString;
PCRDetailDS: OleVariant;
var GeneratedSC: OleVariant;
var ErrorMsg: WideString);
type
TPCR_SCID = record
PCRID: integer;
SCID: integer;
end;
TSC2PCRArray = array of TPCR_SCID;
var
SC2PCRArray: TSC2PCRArray;
NewSCID: integer;
Index: integer;
GeneratedSCIDs: string;
function GenaSC(const BuyerID, SeasonID, ProgID, StyleID: integer;
UserName: string): integer;
var
SCID: integer;
begin
with qryGenSCdo
begin
Append;
SCID := GetLinkDBMaxIDA('T_SC', ErrorMsg);
FieldByName('ID').AsInteger := SCID;
FieldByName('iBuyer_ID').AsInteger := BuyerID;
FieldByName('iSeason').AsInteger := SeasonID;
FieldByName('iProgramID').AsInteger := ProgID;
FieldByName('iStyleID').AsInteger := StyleID;
FieldByName('vCreatedBy').AsString := UserName;
FieldByName('dCreateDate').AsDateTime := now;
Post;
Result := SCID;
end;
end;
function GetCorrectPos(SCID: integer): integer;
var
i: integer;
begin
for i := Low(SC2PCRArray) to High(SC2PCRArray)do
begin
Result := -1;
if SC2PCRArray.SCID = SCID then
begin
Result := i;
Break;
end;
end;
end;
begin
//记录生成的SC的ID,只有这样在生SC以后才可以正确的取出所生成的SC编号
GeneratedSCIDs := '';
try
with qrySavedo
begin
RecordSet := IUnKnown(PCRDetailDS) as _RecordSet;
if RecordCount > 0 then
begin
//得到表结构
with qryGenSCdo
begin
Close;
with Sqldo
begin
Add('Select ID,iBuyer_ID,iSeason,iProgramID,iStyleID,vCreatedBy,dCreateDate');
Add(Format('From %s', [GetOtherDataSource('T_SC')]));
Add('where 1<>1');
end;
Open;----执行到这个地方出错了!!!,其实在调用这个方法时Com+已经启动了一个事务,GetOtherDataSource这个函数只不过是拼凑字符串而已,目的是得到Tmsdbserver.tms.dbo.T_SC这样的一个可以访问链接服务器的字符串而已
end;
//此数组来记录PCR的ID与SCID的对应关系
Setlength(SC2PCRArray, RecordCount);
try
if not FConObj.Connected then
FConObj.Connected := True;
RecordSet.Set_ActiveConnection(FConObj.ConnectionObject);
First;
Index := 0;
while not Eofdo
begin
SC2PCRArray[Index].PCRID := FieldByName('ID').AsInteger;
if FieldByName('cGenSC').AsString = '1' then
begin
//生成一个SC
NewSCID := GenaSC(BuyerID, SeasonID, ProgID, FieldByName('iStyle').AsInteger, UserName);
GeneratedSCIDs := GeneratedSCIDs + ',' + IntToStr(NewSCID);
SC2PCRArray[Index].SCID := NewSCID;
end;
Next;
inc(Index);
end;
//将生成的所有SC存盘
qryGenSC.UpdateBatch(arAll);
GeneratedSCIDs := Copy(GeneratedSCIDs, 2, length(GeneratedSCIDs) - 1);
//取出生成的SC
with qryGenSCdo
begin
Close;
with Sqldo
begin
Clear;
Add('Select ID,vSC_NO');
Add(Format('From %s', [GetOtherDataSource('T_SC')]));
Add(Format('where ID in %s', [GeneratedSCIDs]));
end;
Open;
//要传出去的一个数组
GeneratedSC := VarArrayCreate([0, RecordCount - 1], varVariant);
//根据数组来对PCR进行修改,填上正确的SCNO
while not Eofdo
begin
Index := GetCorrectPos(FieldByName('ID').AsInteger);
if qrySave.Locate('ID', SC2PCRArray[Index].PCRID, []) then
begin
GeneratedSC[Index] := VarArrayof([SC2PCRArray[Index].PCRID, FieldByName('vSC_NO').AsString]);
qrySave.Edit;
qrySave.FieldByName('vSCNO').AsString := FieldByName('vSC_NO').AsString;
Post;
end;
Next;
end;
end;
//更新到数据库
qrySave.UpdateBatch(arAll);
finally
SC2PCRArray := nil;
end;
end;
end;
SetComplete;
except
on E: Exceptiondo
begin
SetAbort;
Errormsg := E.Message;
raise;
end;
end;
end;
2.中间层组件的事务模式使用了"需要事务"
3.在同一方法中执行链接数据库上的存储过程没有问题但若执行查询(查询链接数据库的表---分布式查询)则会出上述错误
附代码如下:
procedure TPCR_Save.GenSC(BuyerID, SeasonID, ProgID: Integer;
const UserName: WideString;
PCRDetailDS: OleVariant;
var GeneratedSC: OleVariant;
var ErrorMsg: WideString);
type
TPCR_SCID = record
PCRID: integer;
SCID: integer;
end;
TSC2PCRArray = array of TPCR_SCID;
var
SC2PCRArray: TSC2PCRArray;
NewSCID: integer;
Index: integer;
GeneratedSCIDs: string;
function GenaSC(const BuyerID, SeasonID, ProgID, StyleID: integer;
UserName: string): integer;
var
SCID: integer;
begin
with qryGenSCdo
begin
Append;
SCID := GetLinkDBMaxIDA('T_SC', ErrorMsg);
FieldByName('ID').AsInteger := SCID;
FieldByName('iBuyer_ID').AsInteger := BuyerID;
FieldByName('iSeason').AsInteger := SeasonID;
FieldByName('iProgramID').AsInteger := ProgID;
FieldByName('iStyleID').AsInteger := StyleID;
FieldByName('vCreatedBy').AsString := UserName;
FieldByName('dCreateDate').AsDateTime := now;
Post;
Result := SCID;
end;
end;
function GetCorrectPos(SCID: integer): integer;
var
i: integer;
begin
for i := Low(SC2PCRArray) to High(SC2PCRArray)do
begin
Result := -1;
if SC2PCRArray.SCID = SCID then
begin
Result := i;
Break;
end;
end;
end;
begin
//记录生成的SC的ID,只有这样在生SC以后才可以正确的取出所生成的SC编号
GeneratedSCIDs := '';
try
with qrySavedo
begin
RecordSet := IUnKnown(PCRDetailDS) as _RecordSet;
if RecordCount > 0 then
begin
//得到表结构
with qryGenSCdo
begin
Close;
with Sqldo
begin
Add('Select ID,iBuyer_ID,iSeason,iProgramID,iStyleID,vCreatedBy,dCreateDate');
Add(Format('From %s', [GetOtherDataSource('T_SC')]));
Add('where 1<>1');
end;
Open;----执行到这个地方出错了!!!,其实在调用这个方法时Com+已经启动了一个事务,GetOtherDataSource这个函数只不过是拼凑字符串而已,目的是得到Tmsdbserver.tms.dbo.T_SC这样的一个可以访问链接服务器的字符串而已
end;
//此数组来记录PCR的ID与SCID的对应关系
Setlength(SC2PCRArray, RecordCount);
try
if not FConObj.Connected then
FConObj.Connected := True;
RecordSet.Set_ActiveConnection(FConObj.ConnectionObject);
First;
Index := 0;
while not Eofdo
begin
SC2PCRArray[Index].PCRID := FieldByName('ID').AsInteger;
if FieldByName('cGenSC').AsString = '1' then
begin
//生成一个SC
NewSCID := GenaSC(BuyerID, SeasonID, ProgID, FieldByName('iStyle').AsInteger, UserName);
GeneratedSCIDs := GeneratedSCIDs + ',' + IntToStr(NewSCID);
SC2PCRArray[Index].SCID := NewSCID;
end;
Next;
inc(Index);
end;
//将生成的所有SC存盘
qryGenSC.UpdateBatch(arAll);
GeneratedSCIDs := Copy(GeneratedSCIDs, 2, length(GeneratedSCIDs) - 1);
//取出生成的SC
with qryGenSCdo
begin
Close;
with Sqldo
begin
Clear;
Add('Select ID,vSC_NO');
Add(Format('From %s', [GetOtherDataSource('T_SC')]));
Add(Format('where ID in %s', [GeneratedSCIDs]));
end;
Open;
//要传出去的一个数组
GeneratedSC := VarArrayCreate([0, RecordCount - 1], varVariant);
//根据数组来对PCR进行修改,填上正确的SCNO
while not Eofdo
begin
Index := GetCorrectPos(FieldByName('ID').AsInteger);
if qrySave.Locate('ID', SC2PCRArray[Index].PCRID, []) then
begin
GeneratedSC[Index] := VarArrayof([SC2PCRArray[Index].PCRID, FieldByName('vSC_NO').AsString]);
qrySave.Edit;
qrySave.FieldByName('vSCNO').AsString := FieldByName('vSC_NO').AsString;
Post;
end;
Next;
end;
end;
//更新到数据库
qrySave.UpdateBatch(arAll);
finally
SC2PCRArray := nil;
end;
end;
end;
SetComplete;
except
on E: Exceptiondo
begin
SetAbort;
Errormsg := E.Message;
raise;
end;
end;
end;