Solved

excel 2007 vba mysql to array hangs

Posted on 2010-09-09
6
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 60

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 60

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 60

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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

705 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