简体   繁体   English

ADO与OLE DB的连接速度太慢

[英]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).. 我正在使用ADO连接和记录集对象来访问Sybase ASE数据库(OLE DB提供程序)。

For example, simply executing a SQL statement looks something like this: (inserting 10000 rows of data) 例如,简单地执行一条SQL语句看起来像这样:(插入10000行数据)

_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 . 两种方法都可以正常工作并产生预期的结果。唯一的问题是它们都非常慢。使用原始sql语句插入10000行数据只需要3到5秒 On the other hand, accomplishing the same task using ADO objects takes 40-50 Seconds !!! 另一方面,使用ADO对象完成相同的任务需要40到50秒 !!!

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?? 我的意思是很明显,直接执行SQL总是比使用ADO之类的工具更快,但是性能差异通常有很大不同吗?

  2. Can the speed bottleneck be attributed mostly to ADO? 能否将速度瓶颈归因于ADO? Or does the problem has to do more with Database (Sybase)..? 还是该问题与数据库(Sybase)有关。

  3. Is there any other way to access OLE DB in C++,, instead of using ADO (Faster alternative)?? 还有什么其他方法可以使用C ++访问OLE DB,而不是使用ADO(更快的替代方法)?

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. 您应该考虑使用Prepared属性,以便SQL查询仅被编译一次。 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: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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