Board index » delphi » access violation when using aggregate functions in ADO/Access 97

access violation when using aggregate functions in ADO/Access 97

Has anyone had any success using SQL aggregate functions (sum, max, etc.) in
a TADODataSet with the MSJet 4.0 OLEDB provider and Access 97 (DB Engine
Type = 4)?  I'm getting an access violation with the following message as
soon as the CommandText is set.  The application then just hangs.  In the
IDE I can use Run/Reset to get control back.  At runtime I just have to can
the application using the task manager.

"Project Reuntrck32.exe raised exception class EAccessViolation with message
'Access violation at address 1B03F393 in module 'MSJET40.DLL'.  Read of
address 8B317404'. Process stopped.  Use Step or Run to continue."

Thanks,
================================================
Ray Porter
Applications Analyst Programmer
Administrative Information Services, UNC-CH
Phone: 966-5878
email: ray_por...@unc.edu
       dra...@email.unc.edu
Home Page: http://www.unc.edu/~dragon/

"Meddle not in the affairs of dragons,
for thou art crunchy and taste good with ketchup."

 

Re:access violation when using aggregate functions in ADO/Access 97


Hi all,
The problem turned out not to be with the SUM function at all (or with any
of the other SQL aggregate functions).  The access violation was being
caused by how I was setting the CommandText property.  Apparently some
parsing goes on as soon as you set that property, not just when the
TADODataSet is opened.

I was setting the CommandText property to a long SQL statement in the
following manner:

with ADODataSet1 do
  begin
    CommandText := 'select sum(amount) as SumOfAmount ';  < Access Violation
here
    CommandText := CommandText + 'from Cash, Batch ';
    CommandText := CommandText + 'where Cash.batch_id = Batch.batch_id';
    Open;
  end;

When I changed the code as follows, the problem disappeared:

var strSQL: string;

With ADODataSet1 do
   begin
      strSQL := 'select sum(amount) as SumOfAmount ';
      strSQL := strSQL + 'from Cash, Batch';
      strSQL := strSQL + 'where Cash.batch_id = Batch.batch_id';
      CommandText := strSQL;
      Open;
   end;

--
================================================
Ray Porter
Applications Analyst Programmer
Administrative Information Services, UNC-CH
Phone: 966-5878
email: ray_por...@unc.edu
       dra...@email.unc.edu
Home Page: http://www.unc.edu/~dragon/

"Meddle not in the affairs of dragons,
for thou art crunchy and taste good with ketchup."

Quote
"Ray Porter" <ray_por...@unc.edu> wrote in message

news:8a3aj4$4tk1@bornews.borland.com...
Quote
> Has anyone had any success using SQL aggregate functions (sum, max, etc.)
in
> a TADODataSet with the MSJet 4.0 OLEDB provider and Access 97 (DB Engine
> Type = 4)?  I'm getting an access violation with the following message as
> soon as the CommandText is set.  The application then just hangs.  In the
> IDE I can use Run/Reset to get control back.  At runtime I just have to
can
> the application using the task manager.

> "Project Reuntrck32.exe raised exception class EAccessViolation with
message
> 'Access violation at address 1B03F393 in module 'MSJET40.DLL'.  Read of
> address 8B317404'. Process stopped.  Use Step or Run to continue."

> Thanks,
> ================================================
> Ray Porter
> Applications Analyst Programmer
> Administrative Information Services, UNC-CH
> Phone: 966-5878
> email: ray_por...@unc.edu
>        dra...@email.unc.edu
> Home Page: http://www.unc.edu/~dragon/

> "Meddle not in the affairs of dragons,
> for thou art crunchy and taste good with ketchup."

Other Threads