Raised exception class $C0000005 with message 'access violation'

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Raised exception class $C0000005 with message 'access violation'

Post by gustavototta »

Hello, how are you?

In my application there is a function to refresh the queries, but sometimes it is returning ACESS VIOLATION in the "OPEN" method. After clicking on "break" the pointer takes the code to the unit "ZDbcCache.pas", more precisely in the procedure TZRowAccessor.SetNull(ColumnIndex: Integer);

Could someone tell me how to solve this problem, please?

I currently use Delphi 10 Seattle with Zeos 8.0.0-beta

Previously with Delphi 7 and Zeos 7.2 the error was not displayed in the same application (I am in the process of migrating from D7 to Delphi Seattle)

Thank you all for your help!

Code: Select all

procedure RefreshQuery(vmo_ParQuery: TZQuery);
begin
   with (vmo_ParQuery as TZQuery) do
   begin
      DisableControls;
      Close;
      Open;
      EnableControls;
   end;
end;
____________


---------------------------
Debugger Exception Notification
---------------------------
Project Prisma5_MD.exe raised exception class $C0000005 with message 'access violation at 0x0075117a: read of address 0xc2b64469'.
You do not have the required permissions to view the files attached to this post.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Raised exception class $C0000005 with message 'access violation'

Post by marsupilami »

Hello,

which database do you use? Could you try to create a small sample application that reproduces the problem? This really can help in tracking the bug down.

Best regards,

Jan
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Re: Raised exception class $C0000005 with message 'access violation'

Post by gustavototta »

Hello,

Database: PostgreSql 9.3
I don't know if I can replicate the error in an isolated application, because our application has many routines to reach the problem. (we also have many external units)

We can think of something you can help us with, maybe a connection with anydesk or something similar.

What you think about?

Thanks!
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Raised exception class $C0000005 with message 'access violation'

Post by marsupilami »

I had a small discussion with the developer who did that part of Zeos. He will take a look today. We hope to be able to give you a more detailed answer tomorrow.
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Re: Raised exception class $C0000005 with message 'access violation'

Post by gustavototta »

Hello how are you?

I understand perfectly, I'm waiting. Thanks in advance for your attention!

Hugs
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Re: Raised exception class $C0000005 with message 'access violation'

Post by gustavototta »

marsupilami wrote: 06.02.2023, 11:38 I had a small discussion with the developer who did that part of Zeos. He will take a look today. We hope to be able to give you a more detailed answer tomorrow.
How are you?

Did you get any response from the ZeosLib developer regarding the access violation we mentioned, please?

Thanks
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Raised exception class $C0000005 with message 'access violation'

Post by marsupilami »

Hello,

yes, I got a response. He tried to reproduce the problem bud couldn't do so. He asked the question wether you use persistent fields, meaning Fields that are created in the Delphi IDE and where you can set properties during design time?

Unfortunately we are tight on time currently - so finding a time where we can access your computer and resolve the problem there is very limited.

Regarding the creation of a minimum working example:
Is there a query where you always get that error? What happens if you copy that form into a new project and try to open that query? What happens if you try to read data in this modified query from an empty table?

Best regards,

Jan
gustavototta
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 02.02.2023, 20:28

Re: Raised exception class $C0000005 with message 'access violation'

Post by gustavototta »

Hello how are you?

We managed to identify a field that was like fkCalculated, that was the problem.

This probably happened when migrating from Delphi 7 to Delphi 10 Seattle, in the past there was no problem and after updating with the new Delphi + Zeos 8.0 it started giving access violation.

Thank you for your attention!
You do not have the required permissions to view the files attached to this post.
h_visli
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 27.09.2024, 03:45

Re: Raised exception class $C0000005 with message 'access violation'

Post by h_visli »

Today I encountered the same problem. (Lazarus 3.4 + ZeosLib 8.0)
I am using TZQuery and TDBGrid to display a query result, and I implemented the sorting functionality by clicking the header of the TDBGrid control.
My query results include a series of fields from the database table as well as three calculated fields. When I click the header of these three calculated fields, a memory access error occurs (clicking non-calculated fields works fine).

The error comes from TZRowAccessor.SetNull() :

Code: Select all

procedure TZRowAccessor.SetNull(ColumnIndex: Integer);
var Data: PPointer;
begin
{$IFNDEF DISABLE_CHECKING}
  CheckColumnIndex(ColumnIndex);
{$ENDIF}
  {$R-}
  if (FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}]] = bIsNotNull) then begin
    Data := @FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}] + 1];
    FBuffer.Columns[FColumnOffsets[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}]] := bIsNull;
    {$IFDEF RangeCheckEnabled}{$R+}{$ENDIF}
    case FColumnTypes[ColumnIndex{$IFNDEF GENERIC_INDEX} - 1{$ENDIF}] of
      stAsciiStream, stBinaryStream, stUnicodeStream:
          PIZLob(Data)^ := nil;
      stBytes, stString, stUnicodeString:
        if Data^ <> nil then begin
          System.FreeMem(Data^);  <----- Error come from this line.
          Data^ := nil;
        end;
      {$IFDEF WITH_CASE_WARNING}else ;{$ENDIF}
    end;
  end;
end;  
Error comes from "System.FreeMem(Data^);"

Here is the sorting code:

Code: Select all

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  bm: TBookmark;
  G: TDBGrid;
  Q: TZQuery;
  S: string;
  imgIdx: integer;
begin
  G := Column.Grid as TDBGrid;
  Q := G.DataSource.DataSet as TZQuery;
  if (Q = nil) or not Q.Active or Q.IsEmpty then exit;
  if (Column.Field.DataType in [ftUnknown, ftBytes, ftVarBytes, ftBLOB,
    ftMemo, ftGraphic, ftFmtMemo, ftWideMemo]) then
    exit;
  bm := Q.GetBookmark;
  Q.DisableControls;
  try
    s := Q.IndexFieldNames;
    if POS(Column.FieldName + ' Desc', s) = 0 then
    begin
      Q.IndexFieldNames := Column.FieldName + ' Desc';
      imgIdx := 1;
    end
    else
    begin
      Q.IndexFieldNames := Column.FieldName;
      imgIdx := 0;
    end;
    Column.Title.ImageIndex := imgIdx;

    if (G.Tag > 0) and (G.Tag <> Column.Index + 1) then
      G.Columns[G.Tag - 1].Title.ImageIndex := -1;
    G.Tag := column.Index + 1;
  finally
    Q.GotoBookmark(bm);
    Q.FreeBookmark(bm);
    Q.EnableControls;
  end;
end; 

I spent an entire afternoon experimenting with why this error occurs, but unfortunately, I couldn't find the cause of the problem.

In the end, I tried to set up TZQuery in the following steps, and it seems that this avoids the memory access error:

1. Add the three calculated fields in TZQuery;
2. Add the SQL query statement in TZQuery.SQL;
3. Set TZQuery.Active=True;
4. Add all the fields from the query results to TZQuery;
5. Setup TDatasource and TDBGrid.


The key step here is Step 1, where all calculated fields must be added first.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Raised exception class $C0000005 with message 'access violation'

Post by marsupilami »

Hello,

I seem to remember that this was fixed in the current 8.0-patches branch. Could you please thest, if it works for you if you download the current version from SVN?

Best regards,

Jan
h_visli
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 27.09.2024, 03:45

Re: Raised exception class $C0000005 with message 'access violation'

Post by h_visli »

OK, It work fine with 8.0-patches branch.
Thank you, @marsupilami.
Last edited by h_visli on 01.10.2024, 04:47, edited 1 time in total.
Post Reply