程序是服务的形式,在2000下没有任何问题,在2003双核的情况下才会出现。
出现的概率不大,每天大概一到两次,出现后服务就挂了。
为了调试,我写在每个语句上面都对ErrorCode进行了改变。Access violation at address 006C6974. Write of address 0112E530下面的代码:代码逻辑比较简单,稍微看一下就能明白。变量定义:
nmg_ADOConnection :TADOConnection//是写日志的过程,可以不用管。
AddLogToFileEx
//NMC_SQLText_UpdateLineInfo 是常量,SQL语句。{-------------------------------------------------------------------------------
功能: 保存用户状态到数据库
过程名: TNEGMMangerState.SaveStateToDataBase
作者: Steven
日期: 2007.06.04
参数:
AID: Integer; //用户ID
AState: Integer; //状态标准
AStateText: string; //状态名称
ALoginOut: Boolean //是否登出
返回值: 无
-------------------------------------------------------------------------------}
procedure TNEGMMangerState.SaveStateToDataBase(AID: Integer;
AState: Integer; AStateText: string; ALoginOut: Boolean);
var
nmm_ADOQu: TADOQuery;
I, ErrorCode: string;
begin
I := '0';
ErrorCode := '0';
try
if Self.nmg_ADOConnection = nil then Exit;
ErrorCode := '1';
nmm_ADOQu := CreateAdoQueryEx(Self.nmg_ADOConnection);
ErrorCode := '2';
if nmm_ADOQu = nil then
begin
ErrorCode := '3';
Exit;
end; with nmm_ADOQu do
begin
try
ErrorCode := '4';
if ALoginOut then
begin
ErrorCode := '5';
SQL.Add(NMC_SQLText_UpdateLineInfo);
end
else begin
ErrorCode := '6';
SQL.Add(NMC_SQLText_UpdateUserLine);
end;
ErrorCode := '7';
SQL.Add(NMC_SQLText_UpdateLineWhere);
ErrorCode := '8';
Parameters.ParamByName('ID').Value := AID;
ErrorCode := '9';
Parameters.ParamByName('E_Name').Value := '';
ErrorCode := '10';
Parameters.ParamByName('Negm_UserStatus').Value := AStateText;
ErrorCode := '11';
Parameters.ParamByName('Negm_IsonLine').Value := AState;
ErrorCode := '12';
if ALoginOut then
begin
ErrorCode := '13';
Parameters.ParamByName('DataObject').Value := 0;
end; try
ErrorCode := '14';
ExecSQLCommand(Self.nmg_MutexHandle, nmm_ADOQu, ecs_Exec);
ErrorCode := '15';
except
on E:Exception do
begin
if nmm_ADOQu = nil then
AddLogToFileEx('nmm_Adoqu is null 11');
AddLogToFileEx(E.Message, 'NEGM_Svr_State->uMain.pas', 'SaveStateToDataBase 11');
end;
end; finally
if not (nmm_ADOQu is TADOQuery) then
AddLogToFileEx('nmm_ADOQu is not valid');
if not (Self is TNEGMMangerState) then
AddLogToFileEx('Self is not valid');
if not (nmg_ADOConnection is TADOConnection) then
AddLogToFileEx('nmg_ADOConnection is not valid');
I := 'free';
FreeAndNil(nmm_ADOQu);
CoUninitialize;
end;
end;
except
on E: Exception do
begin
AddLogToFileEx('dword(@Self) :' + IntToStr(dword(@Self)));
AddLogToFileEx('(PDWORD(Self.nmg_ADOConnection))^ :' + IntToStr((PDWORD(Self.nmg_ADOConnection))^ ));
AddLogToFileEx('dword(@Self.nmg_ADOConnection) :' + IntToStr(dword(@Self.nmg_ADOConnection))); AddLogToFileEx('i = ' + i);
AddLogToFileEx('ErrorCode = ' + ErrorCode); AddLogToFileEx('nmm_intTemp = ' + IntToStr(nmm_intTemp));
if (I <> 'free') and (nmm_ADOQu = nil) then
AddLogToFileEx('nmm_Adoqu is null');
AddLogToFileEx(E.Message, 'NEGM_Svr_State->uMain.pas', 'SaveStateToDataBase');
end;
end;
end;
function CreateAdoQueryEx(AADOConn: TADOConnection): TADOQuery;
begin
Result := nil;
if AADOConn = nil then
begin
Exit;
end;
CoInitialize(nil);
Result := TADOQuery.Create(nil);
try
Result.Connection := AADOConn;
Result.Close;
Result.SQL.Clear;
Result.Parameters.Clear;
except
on E: Exception do
begin
AddLogToFileEx(E.Message, 'uFunction.pas', 'CreateAdoQueryEx');
FreeAndNil(Result);
CoUninitialize;
end;
end;
end;
从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 i = free从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 ErrorCode = 7从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 nmm_intTemp = 1000从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 单元名: NEGM_Svr_State->uMain.pas
过程名: SaveStateToDataBase
////////////////////////////////////////////////ErrorCode = 的值有时候是1、6、11,也就是说随机的。
nmm_intTemp 是Self的一个全局变量,在Self.Create的时候赋值为1000,为了判断出错的时候,Self对象是表示不存在了。
出现的概率不大,每天大概一到两次,出现后服务就挂了。
为了调试,我写在每个语句上面都对ErrorCode进行了改变。Access violation at address 006C6974. Write of address 0112E530下面的代码:代码逻辑比较简单,稍微看一下就能明白。变量定义:
nmg_ADOConnection :TADOConnection//是写日志的过程,可以不用管。
AddLogToFileEx
//NMC_SQLText_UpdateLineInfo 是常量,SQL语句。{-------------------------------------------------------------------------------
功能: 保存用户状态到数据库
过程名: TNEGMMangerState.SaveStateToDataBase
作者: Steven
日期: 2007.06.04
参数:
AID: Integer; //用户ID
AState: Integer; //状态标准
AStateText: string; //状态名称
ALoginOut: Boolean //是否登出
返回值: 无
-------------------------------------------------------------------------------}
procedure TNEGMMangerState.SaveStateToDataBase(AID: Integer;
AState: Integer; AStateText: string; ALoginOut: Boolean);
var
nmm_ADOQu: TADOQuery;
I, ErrorCode: string;
begin
I := '0';
ErrorCode := '0';
try
if Self.nmg_ADOConnection = nil then Exit;
ErrorCode := '1';
nmm_ADOQu := CreateAdoQueryEx(Self.nmg_ADOConnection);
ErrorCode := '2';
if nmm_ADOQu = nil then
begin
ErrorCode := '3';
Exit;
end; with nmm_ADOQu do
begin
try
ErrorCode := '4';
if ALoginOut then
begin
ErrorCode := '5';
SQL.Add(NMC_SQLText_UpdateLineInfo);
end
else begin
ErrorCode := '6';
SQL.Add(NMC_SQLText_UpdateUserLine);
end;
ErrorCode := '7';
SQL.Add(NMC_SQLText_UpdateLineWhere);
ErrorCode := '8';
Parameters.ParamByName('ID').Value := AID;
ErrorCode := '9';
Parameters.ParamByName('E_Name').Value := '';
ErrorCode := '10';
Parameters.ParamByName('Negm_UserStatus').Value := AStateText;
ErrorCode := '11';
Parameters.ParamByName('Negm_IsonLine').Value := AState;
ErrorCode := '12';
if ALoginOut then
begin
ErrorCode := '13';
Parameters.ParamByName('DataObject').Value := 0;
end; try
ErrorCode := '14';
ExecSQLCommand(Self.nmg_MutexHandle, nmm_ADOQu, ecs_Exec);
ErrorCode := '15';
except
on E:Exception do
begin
if nmm_ADOQu = nil then
AddLogToFileEx('nmm_Adoqu is null 11');
AddLogToFileEx(E.Message, 'NEGM_Svr_State->uMain.pas', 'SaveStateToDataBase 11');
end;
end; finally
if not (nmm_ADOQu is TADOQuery) then
AddLogToFileEx('nmm_ADOQu is not valid');
if not (Self is TNEGMMangerState) then
AddLogToFileEx('Self is not valid');
if not (nmg_ADOConnection is TADOConnection) then
AddLogToFileEx('nmg_ADOConnection is not valid');
I := 'free';
FreeAndNil(nmm_ADOQu);
CoUninitialize;
end;
end;
except
on E: Exception do
begin
AddLogToFileEx('dword(@Self) :' + IntToStr(dword(@Self)));
AddLogToFileEx('(PDWORD(Self.nmg_ADOConnection))^ :' + IntToStr((PDWORD(Self.nmg_ADOConnection))^ ));
AddLogToFileEx('dword(@Self.nmg_ADOConnection) :' + IntToStr(dword(@Self.nmg_ADOConnection))); AddLogToFileEx('i = ' + i);
AddLogToFileEx('ErrorCode = ' + ErrorCode); AddLogToFileEx('nmm_intTemp = ' + IntToStr(nmm_intTemp));
if (I <> 'free') and (nmm_ADOQu = nil) then
AddLogToFileEx('nmm_Adoqu is null');
AddLogToFileEx(E.Message, 'NEGM_Svr_State->uMain.pas', 'SaveStateToDataBase');
end;
end;
end;
function CreateAdoQueryEx(AADOConn: TADOConnection): TADOQuery;
begin
Result := nil;
if AADOConn = nil then
begin
Exit;
end;
CoInitialize(nil);
Result := TADOQuery.Create(nil);
try
Result.Connection := AADOConn;
Result.Close;
Result.SQL.Clear;
Result.Parameters.Clear;
except
on E: Exception do
begin
AddLogToFileEx(E.Message, 'uFunction.pas', 'CreateAdoQueryEx');
FreeAndNil(Result);
CoUninitialize;
end;
end;
end;
从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 i = free从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 ErrorCode = 7从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 nmm_intTemp = 1000从属模块: D:\netmarch\NTService\Plugins\NEGM_Svr_State.dll
09:01:33 单元名: NEGM_Svr_State->uMain.pas
过程名: SaveStateToDataBase
////////////////////////////////////////////////ErrorCode = 的值有时候是1、6、11,也就是说随机的。
nmm_intTemp 是Self的一个全局变量,在Self.Create的时候赋值为1000,为了判断出错的时候,Self对象是表示不存在了。
dbedit14.text:=datamodule2.products.fieldbyname('Calculatedtotalsizes').asstring;
谁能帮我解释一下?
难道Result.Connection := AADOConn;也会造成访问冲突?“用单步调试, 看看CPU 0112E530处是什么代码”
这个问题是随机出现,一天也就1到2次,而且在开发的机器上没有问题,即时可以调试,就这个出现的概率,一天就在这个地方设置断点不停的F7或者F8,我想很难受了。