Solved

Slow connection between VB and Mysql

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

861 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