Solved

excel 2007 vba mysql to array hangs

Posted on 2010-09-09
6
751 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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,…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

708 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

16 Experts available now in Live!

Get 1:1 Help Now