急!急!!急!!! ServerSocket中使用DB时出现奇怪的问题(100分)

  • 主题发起人 主题发起人 zaoya
  • 开始时间 开始时间
Z

zaoya

Unregistered / Unconfirmed
GUEST, unregistred user!
在ServerSocket的ClientExecute中有打开TDataBase&TQuery语句
1.若Client(用Java Applet)中Stream未连接Server时,
可以正常关闭Server窗口
2.若Client中Stream连接Server后关闭Server窗口则出现异常

注:1.TDataBase&TQuery都是在ClientExecute动态Create,并且
SessionName,DataBaseName也是唯一的(参见Demo/DB/bkquerys)
2.如果需要源代码,告知一声
 
贴源码吧!
 
看看原码吧!快点:)
 
对不起,前几日有事,原码如下:
type
THBServerThread = class(TServerClientThread)
private
Dm: TDM1;
procedure HandleRequest(const pRecvD: PChar);
public
constructor Create(CreateSuspended: Boolean; ASocket: TServerClientWinSocket);
procedure Destroy; override;
procedure ClientExecute; override;
end;

var
Guard: Integer;
Numbers: Integer;

{ Thread safe increment of Numbers to guarantee the result is unique }
function GetUniqueNumber: Integer;
asm
@@1: MOV EDX,1
XCHG Guard,EDX
OR EDX,EDX
JNZ @@2
MOV EAX,Numbers
INC EAX
MOV Numbers,EAX
MOV Guard,EDX
RET

@@2: PUSH 0
CALL Sleep
JMP @@1
end;

constructor THBServerThread.Create(CreateSuspended: Boolean; ASocket: TServerClientWinSocket);
begin
inherited;
KeepInCache:=False; //本想每次线程执行后释放,以便debug,但不成
end;

procedure Destroy;
begin
dm.free;
inherited;
end;

procedure THBServerThread.ClientExecute;
var
UniqueNumber: Integer;
Data: array[0..63] of Char; //每次Read读出的数据
Temp: array[0..127] of Char;
ifRecv,Loop: boolean;
SocketStream: TWinSocketStream;
begin
{ Ensure the Query has a unique session and database. A unique
session is required for each thread. Since databases are
session specific it must be unique as well }
UniqueNumber := GetUniqueNumber;
Session.SessionName := Format('%s%x', [Session.Name, UniqueNumber]);
Dm:=TDm1.Create(Application);
Dm.DB.SessionName:=Session.SessionName;
Dm.DB.DatabaseName := Format('HbWeb%x', [UniqueNumber]);
Dm.DB.Connected:=True;
Dm.Qry.SessionName:=Dm.DB.SessionName;
Dm.Qry.DatabaseName:=Dm.DB.DatabaseName;
while not Terminated and ClientSocket.Connected do
try
SocketStream := TWinSocketStream.Create(ClientSocket, 60000);
try
Loop:=True;
ifRecv:=False;
FillChar(Temp,SizeOf(Temp),0);
while Loop do begin
//这里有一点奇怪,第一次Read时总是只读一个byte,Why?
FillChar(Data, SizeOf(Data), 0);
if SocketStream.WaitForData(60000) then begin
if SocketStream.Read(Data, SizeOf(Data)) = 0 then begin
ClientSocket.Close;
Terminate;
Break;
end else
StrLCat(Temp,Data,128);
if not (StrPos(Temp,#13#10)=nil) then begin
Loop:=False;
ifRecv:=True;
end;
end
else begin // if SocketStream.WaitForData(60000) then
ClientSocket.Close;
Terminate;
Loop:=False;
ifRecv:=False;
end;
end; //while Loop do
if ifRecv and ClientSocket.Connected then
HandleRequest(Temp); //进行相应处理
finally
SocketStream.Free;
end;
except
//HandleException;
Dm.Free;
Terminate;
end;
end;

procedure THBServerThread.HandleRequest(const pRecvD: PChar);
//此过程用于处理Client的请求,debug无问题
 
如果将TDm及TQuery移出Thread,即将Query中数据存在一数组中,
此时,在Delphi4的集成环境下无问题,但脱离集成环境运行时,
出现错误提示
“Access violation at address xxxxxxx in module 'dao350.dll'".
如果需要Delphi原码和Java Applet原码,我可Email过去.
 
因有人盗用本人帐户,故改用新的用户名spear,请各们留意。
 
Server窗口则出现异常时的错误信息?
 
可以肯定的是由于DB引起的。当把对Dataset的处理从thread
移出来时,程序没有错误,但在thread中时就有以上异常。
 
多人接受答案了。
 
后退
顶部