Solved

excel 2007 vba mysql to array hangs

Posted on 2010-09-09
6
754 Views
Last Modified: 2012-05-10
We have the used the following routine many times in our Excel 2007 vba to get the full record set from the mysql database to an array and it has always worked in the past.  Now when we try with the data base at just over 14,000 records (and about 65 columns in each record) Excel will hang on the statement  myArray = rs.GetRows().  We are using uwamp as the server with mysql at version 5.1.41.  Can anyone advise on why this may be occuring.

ConnectDB
Set rs = New ADODB.Recordset
sqlstr = "SELECT * FROM members ORDER BY account_lastname ASC, account_firstname ASC"
rs.Open sqlstr, conn, adOpenDynamic, adLockOptimistic

maxarow = 0
If Not rs.EOF Then
  myArray = rs.GetRows()
  maxacol = UBound(myArray, 1)
  maxarow = UBound(myArray, 2)
0
Comment
Question by:digital-servers
  • 3
  • 2
6 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33646571
digital-servers,

Try loading the latest ODBC connector for MySQL:
http://www.mysql.com/downloads/connector/odbc/

Additionally, if this worked fine before and the only difference now is the size of the data, I would check your indexes (explain plan for query) and see if that and/or your MySQL server configuration need to be tuned any.

Here is a nice reference:
3 Ways to Speed Up MySQL
by gr8gonzo - http:M_124884.html

Regards,

Kevin
0
 

Author Comment

by:digital-servers
ID: 33646611
I believe we have found a solution.

we added this line
rs.CursorLocation = adUseClient
right after the line
Set rs = New ADODB.Recordset

The command  "rs.CursorLocation = adUseClient"  caches the recordset rows on the local machine instead of the database server.  

The routine seems to work and Excel does not hang.  Transfer was quick with just a slight pause at   myArray = rs.GetRows() when stepping through the visual basic code.

0
 

Author Closing Comment

by:digital-servers
ID: 33646640
Issue is solved
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33646677
Glad you found that.  Yes, figured the issue was in the query cache or other configuration settings on MySQL due to the size of the query now that your results have grown.  Nice simple solution, but I would still look to performance tune the query and MySQL so that as your data grows you don't see other issues ...

Best regards and happy coding,

Kevin
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 33650237
Thanks, digital-servers!
I appreciate the recognition for helping you in any way I could.

Best regards and happy coding,
Kevin
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now