Solved

Slow connection between VB and Mysql

Posted on 2004-10-06
7
457 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
[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
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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 need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

751 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