Automation Error
-
Hi everyone, I'm having trouble with an Access query. My program does one connection to the db and several queries, but only the first one is going through, the second one throws Error '-2147417851 (8001015)' which is an automation error. I'v searched for the cause and it says it's because the server is throwing an exception. I read in Microsoft's support site and found out that I need to do late binding, but I believe that's what I'm doing. The code is this:
int CDBAccess::cargaConfig(char *pszComponente, CConfig *poConfig) { _RecordsetPtr rs; HRESULT hr; _variant_t conn; char szQuery[256]; char szTemp[30]; FieldPtr campo; try { hr = rs.CreateInstance("ADODB.Recordset"); if(FAILED(hr)) { m_nError = 506;//error al crear rs return m_nError; } conn = (IDispatch*) m_Conec; } catch(_com_error & err) { MessageBox(NULL,(LPCTSTR) err.Description(), "CargaConfig", MB_OK); return -1; } //se hace el query sprintf(szQuery, "select * from configuracion where componente = '%s'", pszComponente); _bstr_t qry(szQuery); FILE *fd; fd = fopen("C:\\usr\\sia\\query.txt","w"); fprintf(fd,"%s",(char *)qry); fclose(fd); //MessageBox(NULL,(char *)qry, "cargaConfig",0); try { hr = rs->Open(qry, conn, adOpenStatic, adLockOptimistic, adCmdText); if(FAILED(hr)) { m_nError = 507;//error al abrir rs return m_nError; } } catch(_com_error & err) { MessageBox(NULL,(LPCTSTR) err.Description(), "CargaConfig", MB_OK); return -1; } try { //se leen los datos campo = rs->Fields->Item["timeout"]; _bstr_t to = campo->Value; sprintf(szTemp, "%s", (char *)to); poConfig->iTimeout = atoi(szTemp); campo = rs->Fields->Item["canal_comunicacion"]; _bstr_t can = campo->Value; sprintf(poConfig->szCanalComm, "%s", (char *)can); campo = rs->Fields->Item["id_canal"]; _bstr_t idcan = campo->Value; sprintf(poConfig->szIdCanal, "%s", (char *)idcan); campo = rs->Fields->Item["objeto"]; _bstr_t obj = campo->Value; sprintf(poConfig->szObjeto, "%s", (char *)obj); campo = rs->Fields->Item["prioridad"]; _bstr_t pri = campo->Value; sprintf(poConfig->szPriori, "%s", (char *)pri); hr = rs->Close(); if(FAILED(hr)) { m_nError = 508;//error al cerrar rs return m_nError; } //rs = NULL; } catch(_com_error & err) { MessageBox(NULL,(LPCTSTR)err.Description(),"CargaConfig",0); return -1; }
-
Hi everyone, I'm having trouble with an Access query. My program does one connection to the db and several queries, but only the first one is going through, the second one throws Error '-2147417851 (8001015)' which is an automation error. I'v searched for the cause and it says it's because the server is throwing an exception. I read in Microsoft's support site and found out that I need to do late binding, but I believe that's what I'm doing. The code is this:
int CDBAccess::cargaConfig(char *pszComponente, CConfig *poConfig) { _RecordsetPtr rs; HRESULT hr; _variant_t conn; char szQuery[256]; char szTemp[30]; FieldPtr campo; try { hr = rs.CreateInstance("ADODB.Recordset"); if(FAILED(hr)) { m_nError = 506;//error al crear rs return m_nError; } conn = (IDispatch*) m_Conec; } catch(_com_error & err) { MessageBox(NULL,(LPCTSTR) err.Description(), "CargaConfig", MB_OK); return -1; } //se hace el query sprintf(szQuery, "select * from configuracion where componente = '%s'", pszComponente); _bstr_t qry(szQuery); FILE *fd; fd = fopen("C:\\usr\\sia\\query.txt","w"); fprintf(fd,"%s",(char *)qry); fclose(fd); //MessageBox(NULL,(char *)qry, "cargaConfig",0); try { hr = rs->Open(qry, conn, adOpenStatic, adLockOptimistic, adCmdText); if(FAILED(hr)) { m_nError = 507;//error al abrir rs return m_nError; } } catch(_com_error & err) { MessageBox(NULL,(LPCTSTR) err.Description(), "CargaConfig", MB_OK); return -1; } try { //se leen los datos campo = rs->Fields->Item["timeout"]; _bstr_t to = campo->Value; sprintf(szTemp, "%s", (char *)to); poConfig->iTimeout = atoi(szTemp); campo = rs->Fields->Item["canal_comunicacion"]; _bstr_t can = campo->Value; sprintf(poConfig->szCanalComm, "%s", (char *)can); campo = rs->Fields->Item["id_canal"]; _bstr_t idcan = campo->Value; sprintf(poConfig->szIdCanal, "%s", (char *)idcan); campo = rs->Fields->Item["objeto"]; _bstr_t obj = campo->Value; sprintf(poConfig->szObjeto, "%s", (char *)obj); campo = rs->Fields->Item["prioridad"]; _bstr_t pri = campo->Value; sprintf(poConfig->szPriori, "%s", (char *)pri); hr = rs->Close(); if(FAILED(hr)) { m_nError = 508;//error al cerrar rs return m_nError; } //rs = NULL; } catch(_com_error & err) { MessageBox(NULL,(LPCTSTR)err.Description(),"CargaConfig",0); return -1; }
Is this the second query that is failing? It looks like your syntax is for SQL Server, using wildcard %. If you are trying to wildcard it, and you are using Access your query needs to say: select * from configuracion where componente like '*s' Otherwise the query will never return any records.