Solved

Slow connection between VB and Mysql

Posted on 2004-10-06
7
450 Views
Last Modified: 2008-01-16
I want to save information from VB to a MySql Table and this is my code:

Set b = New ADODB.Connection
Set t = New ADODB.Recordset
b.Open "Provider=MSDASQL.1;Data Source=test1;User Id=;Password="

Dim t As ADODB.Recordset
Set t = New ADODB.Recordset

SQL = "SELECT * FROM table1"

t.CursorLocation = adUseClient
t.Open SQL, b, adOpenDynamic, adLockOptimistic


        t.AddNew
        t.Fields("ID") = text1
        ....
        t.Update

The problem is that when I open this table "table1" it takes about 7 seconds to open it and it wasnt that way before, I dont know if its because the table is bigger now (30.000 records and about 2.6MB)

What can I do to improve this?

Thanks

0
Comment
Question by:matrix717
  • 2
7 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 12243713
Do you need to retrieve 30,000 records? You can normally filter records to retreive only some records (rarely more then 1000 for most process).
0
 
LVL 2

Accepted Solution

by:
Drifter88zxtW earned 150 total points
ID: 12243793
What is slow? Just opening the connection?

Or is the updating to the table that is slow?

Or is do you not know and are just wondering why the routine is slow?

Are you just adding new a new record with the routine?

Couple things I would do...

If just adding a record. Instead of using a recordset object with .addnew and .update.. just execute a INSERT INTO SQL statment on the database with a command object.

If you need to use a recordset and see if you really need to use adOpenDynamic (slowest option there is). See if you can use adOpenForwardOnly, or if you need to move backward and forward but don't need to see the record right away use adOpenKeyset.

....

From the code you gave I see no reason to query out all your database records. So again instead of filling a recordset with all kinds of records for no reason, just use a insert into sql statment. Your response time will improve dramitcally.

If none of these suggestiions apply to what you are doing, please elaborate on what exactly you are doing with the recordset.

0
 
LVL 1

Expert Comment

by:Lycaon
ID: 12253134
matrix717:

Yeah, your problem with the speed is because when you use a SELECT * on a 30k record table, the server's going to send you all 30k records as a recordset result.  As Drifter mentioned, if you're doing this just to insert a new record into the table, you'd be MUCH better off using an INSERT INTO statement, like so:

b.Execute "INSERT INTO Table1 (ID, SomeOtherField) VALUES ('" & Text1.Text & "'. 'SomeValue';"

(Drifter's explained much more than I have, I'd accept his answer :) )

0
 
LVL 1

Expert Comment

by:Lycaon
ID: 12253144
Oops, my SQL statement is missing a ) right before the semicolon, but you get the idea.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

12 Experts available now in Live!

Get 1:1 Help Now