ADO exception problem
-
I am writing a simple DOS applicaion that is using ADO to connect to data source. The COM libraries are initializing successfully and the connection to database by connection pointer is also established. But when i try to run a "query" using connection pointer, the following exception is raised:
Error:800a0e81.
ErrorMessage:Unknown error 0x800A0E81.
Source:ADODB.Connection.
Description:Operation cannot be performed while connecting asynchronously..Can any one tell me why this happens ??? Here is my code:
\_bstr\_t bstrQuery("SELECT \* FROM Customers"); \_variant\_t vRecsAffected(0L); \_RecordsetPtr pRecordSet;
pRecordSet = m_pConnection->Execute(bstrQuery, &vRecsAffected, adOptionUnspecified);
-
I am writing a simple DOS applicaion that is using ADO to connect to data source. The COM libraries are initializing successfully and the connection to database by connection pointer is also established. But when i try to run a "query" using connection pointer, the following exception is raised:
Error:800a0e81.
ErrorMessage:Unknown error 0x800A0E81.
Source:ADODB.Connection.
Description:Operation cannot be performed while connecting asynchronously..Can any one tell me why this happens ??? Here is my code:
\_bstr\_t bstrQuery("SELECT \* FROM Customers"); \_variant\_t vRecsAffected(0L); \_RecordsetPtr pRecordSet;
pRecordSet = m_pConnection->Execute(bstrQuery, &vRecsAffected, adOptionUnspecified);
Just a stab in the dark, but you might need to create an instance of the Recordset object
_RecordsetPtr pRecordset = NULL; // Create COM instance. You should also test the return code for // this for success. pRecordset.CreateInstance(__uuidof(Recordset)); // // etc. etc..
chin -
Just a stab in the dark, but you might need to create an instance of the Recordset object
_RecordsetPtr pRecordset = NULL; // Create COM instance. You should also test the return code for // this for success. pRecordset.CreateInstance(__uuidof(Recordset)); // // etc. etc..
chinNot worked
-
I am writing a simple DOS applicaion that is using ADO to connect to data source. The COM libraries are initializing successfully and the connection to database by connection pointer is also established. But when i try to run a "query" using connection pointer, the following exception is raised:
Error:800a0e81.
ErrorMessage:Unknown error 0x800A0E81.
Source:ADODB.Connection.
Description:Operation cannot be performed while connecting asynchronously..Can any one tell me why this happens ??? Here is my code:
\_bstr\_t bstrQuery("SELECT \* FROM Customers"); \_variant\_t vRecsAffected(0L); \_RecordsetPtr pRecordSet;
pRecordSet = m_pConnection->Execute(bstrQuery, &vRecsAffected, adOptionUnspecified);
This code must be incomplete. We don't see the code for creating the Connection object. Also, you may want to work only with the recordset object, unless you want to reuse the connection for other queries. Michel It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard -
Not worked
Your original error message mentions something about an asyncronous connection. This may be the root of all your evils :mad: An asyncronous ADO connection requires a lot more construction code that your entire program may be missing. I have done a quick test and it seems to work ok. I've provided the console function below for you to look at.
void ConnectAndDisplay() { CString strSQL; // SQL statement string _variant_t vtAffected; // _variant_t vtField; // _ConnectionPtr pConnection = NULL; // connection smart pointer _RecordsetPtr pRecordset = NULL; // recordset smart pointer strSQL = "Select [Name] From [CustomerTable]"; try { TESTHR( pConnection.CreateInstance(__uuidof(Connection)) ); TESTHR( pRecordset.CreateInstance(__uuidof(Recordset)) ); TESTHR( pConnection->Open( _bstr_t(_T("File \\MyConnection.udl;")), "", "", NULL ) ); // Execute pre-prepared SQL statement pRecordset = pConnection->Execute((LPCTSTR)strSQL, &vtAffected,adOptionUnspecified); // display returned results while( pRecordset->ADOEOF != VARIANT_TRUE ) { _variant_t vtField; CString strField; vtField = pRecordset->Fields->GetItem("Name")->Value; ///////////////////////////////////////// ASSERT( vtField.vt == VT_BSTR ); // we are expecting a string!! //////////////////////////////////////// strField = vtField.bstrVal; cout<< (LPCTSTR)strField << endl; pRecordset->MoveNext(); } pConnection->Close(); } catch(_com_error e) { CString strMessage; strMessage.Format("Error: %s\n", e.ErrorMessage()); AfxMessageBox(strMessage); } return; }
Chin