Solved

Slow connection between VB and Mysql

Posted on 2004-10-06
7
454 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 70

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

832 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