程序是服务的形式,在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对象是表示不存在了。

解决方案 »

  1.   

    我的建议~,直接用ADOInt上的Interface处理ADO连接,不要用VCL的ADO的
      

  2.   

    to:SmallMaker(小人物) ,因为是服务,而且不是经常发生,所以我采用多ErrorCode赋值的方式,尽量多的写当时的情况。Error的值在异常的时候,出现过1、6、7、11,你能判断出来什么问题吗?当然在1的时候,异常是另外一个多了‘'nmm_Adoqu is null'’和程序原来的意思的一样的。
      

  3.   

    多线程中全局变量少用, 用单步调试, 看看CPU 0112E530处是什么代码
      

  4.   

    我这里也是碰到同样的错误提示,原因就是加了以下代码:
    dbedit14.text:=datamodule2.products.fieldbyname('Calculatedtotalsizes').asstring;
    谁能帮我解释一下?
      

  5.   

    to:cncharles(旺仔) 多线程中,用到了一个数据库连接ADOConnection,我觉得对它使用冲突的地方也就是执行SQL语句才会出现问题。这个已经用线程同步做好了。
    难道Result.Connection := AADOConn;也会造成访问冲突?“用单步调试, 看看CPU 0112E530处是什么代码”
    这个问题是随机出现,一天也就1到2次,而且在开发的机器上没有问题,即时可以调试,就这个出现的概率,一天就在这个地方设置断点不停的F7或者F8,我想很难受了。
      

  6.   

    太长了, 对ADOCONNECTION释放是否合理.