Solved

Slow connection between VB and Mysql

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

740 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