简体   繁体   中英

ADO Connection to OLE DB is way too slow

I'm using ADO Connection & Recordset Objects to access a Sybase ASE database (OLE DB Provider)..

For example, simply executing a SQL statement looks something like this: (inserting 10000 rows of data)

_ConnectionPtr ConnPtr;
ConnPtr.CreateInstance("ADODB.Connection");
ConnPtr->Open(....my Connection String, UserID, and Password....);

for (int i=0; i<10000; i++)
    ConnPtr->Execute("INSERT INTO my_table VALUES (1, 2, 3)");

OR (alternative option):

_RecordSet RecPtr; RecPtr.CreateInstance("ADODB.Recordset");
MyObject obj; 

// Construct & Bind obj.. 
...

for (int i=0; i<10000; i++)
    RecPtr->AddNew(&obj);


Both approach works fine and produces the expected result.. The only problem is that they are both extremely slow.. Inserting 10000 rows of data using raw sql statements only takes about 3~5 Seconds . On the other hand, accomplishing the same task using ADO objects takes 40-50 Seconds !!!

So here are some of my questions:

  1. Is this a normal result? I mean it's obvious that direct sql execution is always faster than using something like ADO,, but is the performance difference usually this much different??

  2. Can the speed bottleneck be attributed mostly to ADO? Or does the problem has to do more with Database (Sybase)..?

  3. Is there any other way to access OLE DB in C++,, instead of using ADO (Faster alternative)??

Any insights by people who have alot of experience with database please

You should consider using the Prepared property so that the SQL query only gets compiled once. This is slow for a command's first execution, but, you will get improved performance for subsequent executions:

_ConnectionPtr ConnPtr;
ConnPtr.CreateInstance("ADODB.Connection");
ConnPtr->Open(....my Connection String, UserID, and Password....);
_CommandPtr CmdPtr;
CmdPtr.CreateInstance("ADODB.Command");
CmdPtr->ActiveConnection = ConnPtr;
CmdPtr->CommandText = "INSERT INTO my_table VALUES (1, 2, 3)";
CmdPtr->PutPrepared(true);
for (int i=0; i<10000; i++)
    CommandPtr->Execute(NULL, NULL, adCmdText);

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM