执行存储过程错误(1000分)
我在程序里有一个serversocket侦听5100端口
当收到报文请求时 就创建一个线程
SocketThread := TServerThread.Create(False, ClientSocket);
这个线程会有选择地执行存储过程
前n次好好的,到了n+1次时就会出来一个
access violatino at address 4be345a0 in modulo 'idapi32.dll'
一旦出现这个错误就完了
{******************************************************
* 作者:*****
* 日期:20030805
* 功能:socket线程类
* 此线程当用户请求时启动用来执行存储过程并将结果返回用户
*******************************************************
}
type
TServerThread = class(TServerClientThread)
private
strLength : integer ; //报文长度
strTradeCode : string ; //交易码
strSerNO : string ; //流水号
strParameters : string ; //参数
strReturn : string ; //返回值
Msg : string;
public
procedure ClientExecute; override ; //主控
procedure WriteLog; //写日志
procedure Trade7301; //7301交易
procedure Trade7302; //7302交易
procedure Trade7303; //7303交易
procedure Trade7304; //7304交易
end;
以下是用于执行存储过程的语句
procedure TServerThread.Trade7301;
var
I:integer;
handleresult,amount,note:string;
iLoop,iNum:integer;
cErrorMsg : string;
begin
with dmglobal.StoredProc7301 do
try
ParamByName('TRANSTYPE').Value := NULL;
ParamByName('UID').AsString := copy(strParameters,9,6);
ParamByName('BANKCODE').Value := NULL;
ParamByName('SAVINGACCOUNT').Value := NULL;
ParamByName('PAYTRANSCODE').Value := NULL;
ParamByName('CONTRACTNO').AsString := copy(strParameters,1,8);
ParamByName('AMOUNT').AsString := ''; //output
ParamByName('MONEYTYPE').Value := NULL;
ParamByName('AS400SERIAL').Value := NULL;
ParamByName('PID').Value := NULL;
ParamByName('PAYSERIAL').Value := NULL;
ParamByName('TRANSTIME').Value := NULL;
ParamByName('STOCKTRANSPIN').Value := NULL;
ParamByName('CRYPTOGRAM').Value := NULL;
ParamByName('HANDLERESULT').AsString := ''; //output
ParamByName('OLDBALANCE').Value := NULL;
ParamByName('NOTE').AsString := ''; //output
if not Prepared then Prepare;
ExecProc;
handleresult := copy(ParamByName('handleresult').AsString,1,2);
if (handleresult='99') or (handleresult='21') then //99成功 //21 已缴费
begin
amount := copy(ParamByName('amount').AsString,1,13);
note := ParamByName('note').AsString;
while length(amount)<13 do amount:='0'+amount;
if copy(note,131,4)='未销' then note:=copy(note,1,134)+' '+copy(note,135,5); //未销
if length(note)<147 then
begin
handleresult:='04';
amount:= '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '返回码note长度不够'+note;
exit;
end;
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '交易成功.';
Close;
end else
if (handleresult='39') or (handleresult='40') or (handleresult='03') then //39气费为0 //40超期 //03无此户号
begin
amount:= '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '39气费为0 40超期 03无此户号.';
end else
begin
handleresult := '06';
amount := '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note; //未知返回码handleresult
Msg := '未知返回码'+handleresult;
end;
except
on E: Exception do
begin
handleresult:='00';
amount:= '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '执行后台oracle存储过程QUERYBAL时遇到一个错误.错误信息:'+E.Message;
WriteLog;
if pos('address',E.Message)>0 then
begin
clientsocket.SendText(strReturn);
Msg := '致命错误,异常ODBC连接!系统退出!';
WriteLog;
halt(0);
end;
if (E is EDBEngineError) then
begin
iNum:=(E as EDBEngineError).ErrorCount; // 取错误的总数
// 循环取每个错误的号和信息
for iLoop:=0 to iNum-1 do
begin
cErrorMsg := (E as EDBEngineError).Errors[iLoop].Message; //取错误号
if pos('ORA-03114',cErrorMsg)>0 then
begin
Msg := '数据库失去连接,系统将尝试重新连接oracle数据库...';
WriteLog;
if not frmmain.ConnectOracle then
begin
Msg := '重新连接oracle数据库失败,系统稍候将会重新连接.';
WriteLog;
end
else
begin
Msg := '重新连接oracle数据库成功.';
WriteLog;
try
if not Prepared then Prepare;
ExecProc;
handleresult := copy(ParamByName('handleresult').AsString,1,2);
if (handleresult='99') or (handleresult='21') then //99成功 //21 已缴费
begin
amount := copy(ParamByName('amount').AsString,1,13);
note := ParamByName('note').AsString;
while length(amount)<13 do amount:='0'+amount;
if copy(note,131,4)='未销' then note:=copy(note,1,134)+' '+copy(note,135,5); //未销
if length(note)<147 then
begin
handleresult:='04';
amount:= '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '返回码note长度不够'+note;
exit;
end;
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '交易成功.';
Close;
end else
if (handleresult='39') or (handleresult='40') or (handleresult='03') then //39气费为0 //40超期 //03无此户号
begin
amount:= '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '39气费为0 40超期 03无此户号.';
end else
begin
handleresult := '06';
amount := '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note; //未知返回码handleresult
Msg := '未知返回码'+handleresult;
end;
except
on E: Exception do
begin
handleresult:='00';
amount:= '0000000000000';
note:='';
for I:=0 to 147 do note:=note+'0';
self.strReturn:='0174'+strSerNO+handleresult+amount+note;
Msg := '执行后台oracle存储过程QUERYBAL时遇到一个错误.错误信息:'+E.Message;
WriteLog;
end;
end;
end;
end;
end;
end;
end;
end;
end;