Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Posts
    19

    Unanswered: Fail to execute SQL command asynchronously

    Hi,

    I want to invoke a SQL command “INSERT INTO …” for 3, 000, 000 times to insert 3, 000, 000 records via ADO.

    Other than the BULK INSERT command, I also want to utilize the ADO.Command object to execute the SQL command asynchronously.

    So I do as follows:

    _bstr_t strSQLChange("INSERT INTO MyTable VALUES (1, 2, 3);");

    _ConnectionPtr pConnection = NULL;
    _CommandPtr pCmdChange = NULL;

    // Open connection.
    pConnection.CreateInstance(__uuidof(Connection));
    pConnection->Open (strCnn, "", "", adConnectUnspecified);

    // Create command object.
    pCmdChange.CreateInstance(__uuidof(Command));
    pCmdChange->ActiveConnection = pConnection;
    pCmdChange->CommandText = strSQLChange;

    for (UINT uIndex = 0; uIndex < 3000000, uIndex ++)
    pCmdChange->Execute(NULL, NULL, adCmdText | adAsyncExecute | adExecuteNoRecords);

    The first execution is OK. But the second one will cause the following error

    “Operation cannot be performed while connecting asynchronously”

    Does that means the ADO command object cannot execute the SQL command asynchronously? Thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    It more likely means you can not issue multiple asynchronous commands on the same command object. If the previous command's state is "running" (can't remember offhand what the actual code/value is), then the command object should choke.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •