Welcome to the CC ++ programming Community Forum and interact with 3 million technical staff. Recently, a strange error occurred while accessing the Access database using ADO. I think it is necessary to record it, share with you. Environment win7x86 system; VS2012 compiler; Office2010; Access2000 ~ Access2003 connection string to establish database connection
Welcome to the C/C ++ programming Community Forum and interact with 3 million technical staff> A strange error occurred when I recently accessed the Access database using ADO, I think it is necessary to record it and share it with you. Environment: win7 x86; VS2012 compiler; Office2010; Access2000 ~ Access2003 connection string to establish database connection
Welcome to the C/C ++ programming Community Forum and interact with 3 million technical staff> enter
Recently, When I accessed the Access database using ADO, I encountered a strange error. I think it is necessary to record it and share it with you.
Environment
Win7 x86 system;
VS2012 compiler;
Office2010;
Access2000 ~ Access2003 connection string to establish a database connection.
Key database operation code
BOOL CAccessDatabase: Query (const CString strSQLString, UINT nFieldNumber, vector > & VecvecVariant)
{
_ Variant_t Variant;
Vector <_ variant_t> vecVariant;
Entercriticalkaline (& m_cs );
_ RecordsetPtr pRecordset = NULL;
HRESULT hr = S_FALSE;
Try
{
Hr = pRecordset. CreateInstance (_ T ("ADODB. Recordset "));
If (SUCCEEDED (hr ))
{
Hr = pRecordset-> Open (strSQLString. AllocSysString (), m_pConnection.GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adCmdText );
If (SUCCEEDED (hr ))
{
If (! PRecordset-> adoEOF)
{
Hr = pRecordset-> MoveFirst ();
If (SUCCEEDED (hr ))
{
While (! (PRecordset-> adoEOF ))
{
VecVariant. clear ();
For (UINT I = 0; I <nFieldNumber; ++ I)
{
ZeroMemory (& Variant, sizeof (Variant ));
Variant = pRecordset-> GetCollect (_ variant_t (long) I ));
VecVariant. push_back (Variant );
}
VecvecVariant. push_back (vecVariant );
Hr = pRecordset-> MoveNext ();
}
}
Else
{
M_pLogFile-> WriteLog (GetLastError (), _ T ("an error occurred when moving the record set pointer to the header "));
If (pRecordset-> GetState ()! = AdStateClosed)
{
Hr = pRecordset-> Close ();
If (FAILED (hr ))
{
M_pLogFile-> WriteLog (GetLastError (), _ T ("failed to close record set "));
}
Else
{
M_pLogFile-> WriteLog (GetLastError (), _ T ("record set disabled "));
}
}
If (pRecordset! = NULL)
{
PRecordset. Release ();
PRecordset = NULL;
}
Leavecriticalkaline (& m_cs );
Return FALSE;
}
}
Else
{
M_pLogFile-> WriteLog (GetLastError (), _ T ("the queried record set is empty "));
}
}
Else
{
M_pLogFile-> WriteLog (GetLastError (), _ T ("failed to open record set "));
If (pRecordset! = NULL)
{
PRecordset. Release ();
PRecordset = NULL;
}
Leavecriticalkaline (& m_cs );
Return FALSE;
}
}
Else
{
M_pLogFile-> WriteLog (GetLastError (), _ T ("failed to initialize record set "));
PRecordset = NULL;
Leavecriticalkaline (& m_cs );
Return FALSE;
}
}
[1] [2]