Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Long wait query in Excel VBA

Posted on 2015-01-09
3
Medium Priority
?
204 Views
Last Modified: 2015-01-26
I have a long wait query in Excel VBA :

  Rs.Open stSQL, conn, adOpenKeyset, adLockReadOnly  (take 20 - 25mins)

Current, whole Excel may be grey out or white screen. Is it possible to improve give some progress for the result of the SQL connection status such that user will not abnormally end the VBA application,.. Tks
0
Comment
Question by:AXISHK
  • 2
3 Comments
 
LVL 18

Assisted Solution

by:Simon
Simon earned 2000 total points
ID: 40542133
There are a number of possible reasons. You don't specify what your stSQL query string is, but it could be complex, returning millions of records. Performance will obviously also depend on the data source that you're connecting to. Is it a Microsft SQL Server or something else?

How long is the wait if you use a query that returns just one row from a single table?

Is a keyset type recordset necessary? If you are not updating the records, consider the default adOpenForwardOnly.

I'd suggest you refer to the ADO recordset.open documentation on MSDN, and experiment with the command and execute options.

If possible, check how long it takes to run the same query from another client (e.g. paste the SQL statement into the MS Access query builder) or use the Excel connection wizard to create your database connection and use your SQL statement in the properties tab. If the data source is an RDBMS and you have access to its management tools (e.g. SSMS), try the query directly from there. That also has the benefit of showing you the execution plan. You may be able to optimise your query or add indexes to dramatically improve performance.

Other useful sources for you to look at would be:
ADO performance best practices on Technet
SQLMag - VB Toolkit - Tweaking ADO for Performance
0
 

Author Comment

by:AXISHK
ID: 40543648
The query really take 20 min to complete, testing on the SQL Server Query window.

Just looking for a way to increase interaction on the Excel VBA, say the progress of the TSQL query for example, Tks
0
 
LVL 18

Accepted Solution

by:
Simon earned 2000 total points
ID: 40543820
Sorry, I mis-read your question.

I'd suggest you look at How To Use the ADO FetchProgress and FetchComplete Events on Microsoft Support, possibly in conjunction with a progress bars, possibly in conjunction with AlainByrden's VBA progress bar article.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question