首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

数据库Access violation 有关问题,实在是搞不明白,快被它搞疯了

2012-03-15 
数据库Access violation 问题,实在是搞不明白,快被它搞疯了。程序是服务的形式,在2000下没有任何问题,在200

数据库Access violation 问题,实在是搞不明白,快被它搞疯了。
程序是服务的形式,在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对象是表示不存在了。

[解决办法]
你不能定位到是那句话出错的吗
[解决办法]
多线程中全局变量少用, 用单步调试, 看看CPU 0112E530处是什么代码
[解决办法]
我这里也是碰到同样的错误提示,原因就是加了以下代码:
dbedit14.text:=datamodule2.products.fieldbyname( 'Calculatedtotalsizes ').asstring;
谁能帮我解释一下?
[解决办法]
太长了, 对ADOCONNECTION释放是否合理.
[解决办法]
操作系统装个双核补丁

热点排行