Board index » delphi » TQuery Access Violations

TQuery Access Violations


2005-04-07 02:51:36 AM
delphi169
I am using D7.1, BDE 5.2.0.2, ODBC, and MS SQL Server 2000. Switching away
from the BDE is not possible at the moment (3000+ queries).
I am getting access violations when opening multiple TQuery components (more
than 5 and less than 10).
There doesn't seem to be a set number that causes the error. I have checked
by commenting out a query here and a query there and the error goes away. It
isn't specific to any query.
I added FetchAll after the open of all queries hoping that it would help (no
luck).
The majority of the queries are not attached to grids. They are opened,
recursed then closed.
I noticed that it may have something to do with using the Filter property.
Has anyone else encountered this problem? What is the "real" technical
reason for the error? I can work around it, but it is pain to change the
logic to accommodate a "bug" in the BDE/Delphi.
Any comments and/or suggestions would be great.
 
 

Re:TQuery Access Violations

Isaac Alexander writes:
Quote

I am getting access violations when opening multiple TQuery
components (more than 5 and less than 10).

There doesn't seem to be a set number that causes the error. I have
checked by commenting out a query here and a query there and the
error goes away. It isn't specific to any query.

I noticed that it may have something to do with using the Filter
property.

Has anyone else encountered this problem? What is the "real" technical
reason for the error? I can work around it, but it is pain to change
the logic to accommodate a "bug" in the BDE/Delphi.
I've never seen such a problem. My best guess is that you may be
experiencing a memory problem of some sort (i.e. running out). You indicate
3000+ queries, I assume these are spread over a large number of forms and/or
datamodules. What percentage of these are auto-created when the app starts?
If you create these (all or most) in code only when actually needed (instead
of auto-creating), do you also close them when done or are they left open?
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
"The only reason some people get lost in thought is because it's
unfamiliar territory." - Paul Fix
 

Re:TQuery Access Violations

Quote
I've never seen such a problem.
I saw it a long time ago (2-3 years and D5) when I used multiple dynamically
created TQuery components. It would actually shut down the application. I
changed the logic to have only one query open at a time since I didnt need
to show any results until the end.
Quote
My best guess is that you may be
experiencing a memory problem of some sort (i.e. running out). You
indicate
3000+ queries, I assume these are spread over a large number of forms
and/or
datamodules.
Yes. The queries are spread across the different forms (no datamodules other
than the TDatabase one). There are only 10 queries on this form (only 3 are
active at the time of the access violation). There are around 10 queries
active for the entire application at the time of the error.
What percentage of these are auto-created when the app starts?
Quote
If you create these (all or most) in code only when actually needed
(instead
of auto-creating), do you also close them when done or are they left open?
None of the queries are created in code. I tried both ways and when the
queries were created in code, I received the error more often. All of the
queries are separate TQuery components on the form.
I close each query once I have finished cycling through it. The error occurs
on the open of the next query.
Quote

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
"The only reason some people get lost in thought is because it's
unfamiliar territory." - Paul Fix


 

Re:TQuery Access Violations

Isaac Alexander writes:
Quote

What percentage of these are auto-created when the app starts?
>If you create these (all or most) in code only when actually needed
>(instead of auto-creating), do you also close them when done or are
>they left open?

None of the queries are created in code. I tried both ways and when
the queries were created in code, I received the error more often.
All of the queries are separate TQuery components on the form.

I close each query once I have finished cycling through it. The error
occurs on the open of the next query.
How many forms are open though?
Are you using any threads?
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
Those who disdain wealth as a worthy goal for an individual or a
society seem not to realize that wealth is the only thing that can
prevent poverty. - Thomas Sowell
 

Re:TQuery Access Violations

Quote

How many forms are open though?
Three. Main form, and two non-modal forms.
Quote

Are you using any threads?

No. I am not creating any threads manually.
After some more testing, when I encounter the problem in the IDE, I get a
bunch of access violations (never-ending). If not running in the IDE, the
app just exits without calling any of the three forms' OnClose events.
 

Re:TQuery Access Violations

Isaac Alexander writes:
Quote

No. I am not creating any threads manually.

After some more testing, when I encounter the problem in the IDE, I
get a bunch of access violations (never-ending). If not running in
the IDE, the app just exits without calling any of the three forms'
OnClose events.
Have you been able to navigate to the statement corresponding to the first
AV?
Often, when an app just vanishes, it is a symptom of a stack overflow
(recursion problem). Another possibility is a DLL is suffering an error -
that can sometimes cause the executable to be taken down with it with no
warning.
Still seems like there has to be something else contributing to the problem.
I have one project (started way back in Delphi 4, migrated through D5 and D6
since) on about the same scale as yours - 1000s of TQuery components (in my
case spread across ~150 datamodules), and a few other projects somewhat
smaller but still with lots of queries, and I have never encountered this
*except* in the case of using threads.
In addition, users of that major app can essentially open as many forms as
they want - until they run out of memory. Each form will make use of from 1
to a dozen Datamodules. On average there is likely a couple of 100 active
TQuerys at any given time.
I wish I could think of something more to suggest, but I don't know of any
actual problems in the BDE/components that should cause this.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
"Some see private enterprise as a predatory target to be shot, others
as a cow to be milked, but few are those who see it as a sturdy horse
pulling the wagon." - Winston Churchill
 

Re:TQuery Access Violations

Quote

Have you been able to navigate to the statement corresponding to the first
AV?

Yes. It dies on the close of one of the two querys. I took away the local
filtering and dataset recursing and the error still occurs. I just open and
close the queries. It happens by simply doing the following:
Query1.SQL.Text := 'select something from something';
Query1.Open;
Query2.SQL.Text := 'select somethingelse from somethingelse';
Query2.Open;
Query2.Close;
Query1.Close; // endless access violations and app termination
The error occurs regardless of order of opening and closing providing that
they are both open at the same time. Example: Opening Query1 or Query2 first
and/or closing Query1 and/or Query2 first . It always fails on the second
close (Query1 or Query2)
The following code works but I need to have both open at the same time.
Query1.SQL.Text := 'select something from something';
Query1.Open;
Query1.Close;
Query2.SQL.Text := 'select somethingelse from somethingelse';
Query2.Open;
Query2.Close;
Quote
Still seems like there has to be something else contributing to the
problem.
I have one project (started way back in Delphi 4, migrated through D5 and
D6
since) on about the same scale as yours - 1000s of TQuery components (in
my
case spread across ~150 datamodules), and a few other projects somewhat
smaller but still with lots of queries, and I have never encountered this
*except* in the case of using threads.

I am in the same situation. I upgraded from D3 =>D5 =>D7. The form
getting the error is brand new.
Quote

I wish I could think of something more to suggest, but I don't know of any
actual problems in the BDE/components that should cause this.

Too bad. It looks like I have found a reason to use my Software Assurance.
 

Re:TQuery Access Violations

Isaac Alexander writes:
Quote

Yes. It dies on the close of one of the two querys. I took away the
local filtering and dataset recursing and the error still occurs. I
just open and close the queries. It happens by simply doing the
following:

Query1.SQL.Text := 'select something from something';
Query1.Open;
Query2.SQL.Text := 'select somethingelse from somethingelse';
Query2.Open;
Query2.Close;
Query1.Close; // endless access violations and app termination
This, quite simply, should not happen. Can you create a test app that can
reproduce the problem? If so then I would be willing to look at it. There *has*
to be some other reason for the problem - some other code upsetting the app
and the closing of the query is just triggering the "timebomb".
Unfortunately, the culprit could literally be anywhere.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
"A man is likely to mind his own business when it is worth minding,
when it is not, he takes his mind off his own meaningless affairs by
minding other people's business." - Eric Hoffer
 

Re:TQuery Access Violations

Do you have lookup field in the query ?
"Isaac Alexander" <XXXX@XXXXX.COM>writes
Quote
>
>Have you been able to navigate to the statement corresponding to the
first
>AV?
>

Yes. It dies on the close of one of the two querys. I took away the local
filtering and dataset recursing and the error still occurs. I just open
and
close the queries. It happens by simply doing the following:

Query1.SQL.Text := 'select something from something';
Query1.Open;
Query2.SQL.Text := 'select somethingelse from somethingelse';
Query2.Open;
Query2.Close;
Query1.Close; // endless access violations and app termination

The error occurs regardless of order of opening and closing providing that
they are both open at the same time. Example: Opening Query1 or Query2
first
and/or closing Query1 and/or Query2 first . It always fails on the second
close (Query1 or Query2)

The following code works but I need to have both open at the same time.

Query1.SQL.Text := 'select something from something';
Query1.Open;
Query1.Close;
Query2.SQL.Text := 'select somethingelse from somethingelse';
Query2.Open;
Query2.Close;

>Still seems like there has to be something else contributing to the
problem.
>I have one project (started way back in Delphi 4, migrated through D5
and
D6
>since) on about the same scale as yours - 1000s of TQuery components (in
my
>case spread across ~150 datamodules), and a few other projects somewhat
>smaller but still with lots of queries, and I have never encountered this
>*except* in the case of using threads.
>

I am in the same situation. I upgraded from D3 =>D5 =>D7. The form
getting the error is brand new.

>
>I wish I could think of something more to suggest, but I don't know of
any
>actual problems in the BDE/components that should cause this.
>

Too bad. It looks like I have found a reason to use my Software Assurance.


 

Re:TQuery Access Violations

"Barak zabari" <XXXX@XXXXX.COM>writes
Quote
Do you have lookup field in the query ?

Not in the queries being opened and closed, but the main query is displayed
in a grid (TwwDBGrid/Infopower) using a TQuery and TClientDataSet. The main
query grid does have a lookup attached to it.
Some background... the main grid shows records that get checked for business
rules using the "crashing" queries. I update a field in the main grid to
show the results. Users have a lookup/dropdown to state which action they
would like to perform on each record.
Are there issues with having a lookup in a grid? I have used this approach
in other areas too.
 

Re:TQuery Access Violations

"Wayne Niddery [TeamB]" <XXXX@XXXXX.COM>writes
Quote

This, quite simply, should not happen. Can you create a test app that can
reproduce the problem?
I wish I could.
Quote
If so then I would be willing to look at it. There *has*
to be some other reason for the problem - some other code upsetting the
app
and the closing of the query is just triggering the "timebomb".
Unfortunately, the culprit could literally be anywhere.

I was afraid of that. I ran it through SQL Monitor and all queries are
firing correctly. I also ran it through AQTime 4 and no memory leaks. I have
a case open with Borland so hopefully they can enlighten me.
 

Re:TQuery Access Violations

Sorry for the late replay
In certain setting i got errors when i had lookup fields unless i set the
lookup field
LookUpCache :=True;
It took me a long time to find out that in certain cases i get this error a
few times only when i have lookup fields that did got set to cache and since
my help table are more or less static i decide to not work even more trying
to guess why this happen but just take the easy way out and set it up that
way.
"Isaac Alexander" <XXXX@XXXXX.COM>writes
Quote
"Barak zabari" <XXXX@XXXXX.COM>writes
news:42566425$XXXX@XXXXX.COM...
>Do you have lookup field in the query ?
>

Not in the queries being opened and closed, but the main query is
displayed
in a grid (TwwDBGrid/Infopower) using a TQuery and TClientDataSet. The
main
query grid does have a lookup attached to it.

Some background... the main grid shows records that get checked for
business
rules using the "crashing" queries. I update a field in the main grid to
show the results. Users have a lookup/dropdown to state which action they
would like to perform on each record.

Are there issues with having a lookup in a grid? I have used this
approach
in other areas too.


 

Re:TQuery Access Violations

"Barak zabari" <XXXX@XXXXX.COM>writes
Quote
Sorry for the late replay
No problem.
Quote
In certain setting i got errors when i had lookup fields unless i set the
lookup field
LookUpCache :=True;
It took me a long time to find out that in certain cases i get this error
a
few times only when i have lookup fields that did got set to cache and
since
my help table are more or less static i decide to not work even more
trying
to guess why this happen but just take the easy way out and set it up that
way.

I found the error. I opened a case with Borland, so I wanted to hear what
they said before I posted anything. It occurs when manually preparing an
insert query, executing it, then opening more than one query before
unpreparing the insert query. I sent them a simple app that accesses the MS
SQL Server pubs database. I will update the post once Borland gets back to
me.