Board index » delphi » Problems in SQL Server when opening several queries.

Problems in SQL Server when opening several queries.

For instance: I want to open a TQuery (SELECT * FROM TABLE) on a SQL Server
database.
It opens in a fraction of a second, however if I open another TQuery first,
the second query is going to fetch all records which takes ages. Sometimes
it will even produce an error message 'Connection to database in use by
another instance'.
A solution should be to use a different session for each query, but this
would entail rewriting the whole application so I hope there's a better
one.

Help would be very much appreciated.

thanks,
David Jellema

 

Re:Problems in SQL Server when opening several queries.


Quote
> It opens in a fraction of a second, however if I open another TQuery
first,
> the second query is going to fetch all records which takes ages. Sometimes
> it will even produce an error message 'Connection to database in use by
> another instance'.
> A solution should be to use a different session for each query, but this
> would entail rewriting the whole application so I hope there's a better
> one.

That's simply a limitation of Microsoft's client software: one query per
connection.  Borland, to work around the problem, wrote code to fetch all
rows from the first query into a local memory cache and then close the first
query before opening the second.  If your first query returns a lot of rows
then it's going to take a while.  Your options are to limit the number of
rows returned, close the first query yourself, or use a separate connection
for each query.

-Mike

Other Threads