全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2531
推到 Plurk!
推到 Facebook!

Indy + ADO 服务程序的问题

尚未結案
build8502
一般會員


發表:1
回覆:1
積分:0
註冊:2009-03-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-04-27 14:38:34 IP:58.212.xxx.xxx 訂閱
用Indy TCPServer + ADO 写的一个服务程序,运行一段时间偶尔会出现 Access violation 错误和List index out of bounds 错误,在翻阅了之前的一些文章后,查到2篇相关文章:

http://delphi.ktop.com.tw/board.php?cid=30&fid=66&tid=94882

http://delphi.ktop.com.tw/board.php?cid=168&fid=920&tid=94679

我的情况是这样的,每个线程有自己的ADOConnection,在线程内创建的,线程调用Services里的一个Decode()过程进行数据包的解析,Decode()里动态生成ADOQuery组件进行数据库查询和更新操作,代码大致如下:

在Indy线程中创建ADOConnection
[code delphi]
TDecodeThread = class(TIdPeerThread) // indy thread used to decoding the data pack
protected
FADOConn: TADOConnection;
procedure BeforeExecute; override;
procedure AfterExecute; override;
end;

procedure TDecodeThread.BeforeExecute;
begin
CoInitialize(nil);
FADOConn := TADOConnection.Create(nil);
FADOConn.LoginPrompt := False;
FADOConn.ConnectionString := ConnStr;
end;

procedure TDecodeThread.AfterExecute;
begin
if Assigned(FADOConn) then
begin
FADOConn.Connected := False;
FreeAndNil(FADOConn);
end;
CoUnInitialize;
end;
[/code]

在Service中的TCPServer元件的Execute中调用Decode()进行数据的处理

[code delphi]
//TDataServer = class(TService)

procedure TDataServer.TCPServerExecute(AThread: TIdPeerThread);
var
str,strtemp:string;
ActClient: PClient;
begin
if AThread.Connection.Connected and (not Athread.Terminated) then
begin
ActClient := Pointer(AThread.Data);
ActClient.Time_LastAction := Now;

str := AThread.Connection.CurrentReadBuffer;
if str <> '' then
begin
with TDecodeThread(AThread) do
begin
if Assigned(FADOConn) then
DecodeDataPack(FADOConn,str);
end;
end;
end;
end;
[/code]

Decode过程动态生成ADOQuery进行查询和更新

[code delphi]
procedure TDataServer.DecodeDataPack(ADBConn: TADOConnection; ADataPack: string);
var
ADOQry: TADOQuery;
begin
try
ADOQry := TADOQuery.Create(nil)
with ADOQry do
begin
Connection := ADBConn;
Close;
SQL.Clear;
SQL.Text := 'sql text';
Open;
//...
Close;
SQL.Clear;
SQL.Text := 'sql text'
ExecSQL;
end;
finally
ADOQry.Free;
end;
end;
[/code]

出现的问题如下:
1、运行一段时间偶尔出现 List index out of bounds 错误
2、运行一段时间经常性出现 Access violation at address 00000000. Write of address 00000000 和 Access violation at address 00426F63 in module 'dgprs.exe'. Read of
address 00000015 错误

请各位大大帮忙分析分析原因,线程里访问Service中的Decode()过程是否存在冲突的问题?谢谢各位!
編輯記錄
build8502 重新編輯於 2009-04-27 19:59:39, 註解 無‧
Roach
中階會員


發表:59
回覆:104
積分:97
註冊:2002-11-05

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-05-23 11:43:17 IP:114.137.xxx.xxx 訂閱
請問您使用的是BCB5還是6
我之前類似的問題查很久沒什回答
最後去Borland官網問才被建議下載update patch
原來是BCB5.0 ADO元件本身有問題
6.0我沒裝不知道

底下是readme 文件
你到官網下載安裝看看
================================================
C BUILDER 5 ADOExpress UPDATE PACK 1
RELEASE NOTES
================================================
This update resolves issues with the ADO
features in the Enterprise version of
C Builder 5, as well as in the ADOExpress
upgrade to C Builder 5 Professional.
The update is a self-extracting, self-executing
file. Because it refreshes the ADO files in your
current installation, C Builder must be closed
before running the update.

================================================
REQUIREMENTS
C Builder 5, Enterprise version
------------------------------
* Update Pack 1
C Builder 5, Professional version
with the ADOExpress upgrade
------------------------------
* ADOExpress for C Builder 5 Professional,
Update Pack 1
* C Builder 5 Professional, Update Pack 1

================================================
ISSUES RESOLVED IN THIS UPDATE
MDAC 2.6 Compatibility
------------------------------

This update corrects a known issue which affects
certain ADOExpress applications when running
against MDAC 2.6. Most commonly, the following
error is generated when closing an empty dataset:
"Either EOF or BOF is True, or the current record
has been deleted. Requested operation requires a
current record". The same error may also occur
when canceling an edit operation. Affected
applications should be recompiled after the
update is installed.

================================================
HELP UPDATES
Help updates are available at:
http://www.borland.com/techpubs/bcppbuilder

================================================
Copyright ?2000 Inprise Corporation.
All rights reserved.
系統時間:2017-12-12 20:22:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!