CodingFrenzy
February 1st, 2005, 10:05 AM
I have a VC6 project that access' a visual fox pro database via the use of ADO. When I run the project in DEBUG mode everything works fine. When I run it in RELEASED mode on a development machine it also works fine. But when I try running it on a test machine it blows up.
There are multiple tables that I read in. I connect, create a Recordset, iterate through the DB (reading the field values as I go along), close the Recordset, close the connection, and then repeat the process for all other tables. Each table that gets imported has it's own method.
The results are weird as well. The first table will come in fine with no errors or exceptions.
Usually it will hang in the DisconnectADO() method that gets called at the end of the ImportSecondDB() method. But sometimes an exception is thrown that gets caught in the
catch(...). I'm not really sure what's going on here and have already lost close to a week's worth of development time on this. I have provided some code "snipets" bellow. Any help, comments, or suggestions will be most welcomed and greatly appreciated.
HRESULT ClassName::Run()
{
HRESULT hr = S_OK;
for (int i=0; i<2; ++i)
{
switch(i)
{
case 0:
hr = ImportFirstDB();
break;
case 1:
hr = ImportSecondDB();
break;
default:
ASSERT(FALSE);
hr = E_FAIL;
}
}
}
HRESULT ClassName::ImportFirstDB()
{
ado::_ConnectionPtr spConnection;
ado::_RecordsetPtr spRecSet;
CString ostr;
HRESULT hr = S_OK;
_variant_t ovField;
try
{
if (SUCCEEDED(hr = ConnectADO(spConnection, spRecSet)))
{
if (SUCCEEDED(hr = spRecSet->Open(L"SELECT * FROM daily", _variant_t((IDispatch*)spConnection, true), ado::adOpenStatic,ado::adLockReadOnly, ado::adOptionUnspecified)))
{
if (SUCCEEDED(hr = spRecSet->MoveFirst()))
{
while(SUCCEEDED(hr) && !spRecSet->GetadoEOF())
{
ovField = spRecSet->GetCollect("col name");
if (ovField.vt != VT_NULL)
{
ostr = (_bstr_t)ovField;
}
hr = spRecSet->MoveNext();
}
}
}
}
}
catch(_com_error& oE)
{
hr = ProcessError(&oE);
}
catch(...)
{
hr = ProcessConnectionError(spConnection);
}
DisconnectADO(spConnection, spRecSet);
return hr;
}
HRESULT ClassName::ImportSecondDB()
{
ado::_ConnectionPtr spConnection;
ado::_RecordsetPtr spRecSet;
CString ostr;
HRESULT hr = S_OK;
_variant_t ovField;
try
{
if (SUCCEEDED(hr = ConnectADO(spConnection, spRecSet)))
{
if (SUCCEEDED(hr = spRecSet->Open(L"SELECT * FROM daily", _variant_t((IDispatch*)spConnection, true), ado::adOpenStatic,ado::adLockReadOnly, ado::adOptionUnspecified)))
{
if (SUCCEEDED(hr = spRecSet->MoveFirst()))
{
while(SUCCEEDED(hr) && !spRecSet->GetadoEOF())
{
ovField = spRecSet->GetCollect("col name");
if (ovField.vt != VT_NULL)
{
ostr = (_bstr_t)ovField;
}
hr = spRecSet->MoveNext();
}
}
}
}
}
catch(_com_error& oE)
{
hr = ProcessError(&oE);
}
catch(...)
{
hr = ProcessConnectionError(spConnection);
}
DisconnectADO(spConnection, spRecSet);
return hr;
}
HRESULT ClassName::ConnectADO(ado::_ConnectionPtr& spConnection, ado::_RecordsetPtr& spRecSet)
{
CString ostrConnection;
HRESULT hr = S_OK;
try
{
if (SUCCEEDED(hr = spConnection.CreateInstance(__uuidof(ado::Connection))))
{
ostrConnection = _T("Provider=VFPOLEDB.1;");
ostrConnection += _T("Data Source=");
ostrConnection += ostrInputFile + _T(";");
if (SUCCEEDED(hr = spConnection->Open(_bstr_t(ostrConnection), L"", L"", ado::adModeUnknown)))
{
spRecSet.CreateInstance(__uuidof(ado::Recordset));
spRecSet->CursorLocation = ado::adUseClient;
}
else
{
_com_issue_error(hr);
}
}
catch(_com_error &oE)
{
hr = ProcessError(&oE, _T("AccountView_WINTask::ConnectADO() - InputFile: ") + ostrInputFile);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
hr = E_FAIL;
}
return hr;
}
HRESULT ClassName::DisconnectADO(ado::_ConnectionPtr& spConnection, ado::_RecordsetPtr& spRecSet)
{
ASSERT(spConnection);
ASSERT(spRecSet);
HRESULT hr = S_OK;
try
{
if (spRecSet)
{
if (spRecSet->State == ado::adStateOpen)
{
hr = spRecSet->Close();
}
}
if (spConnection)
{
if (spConnection->State == ado::adStateOpen)
{
hr = spConnection->Close();
}
}
spRecSet.Release();
spConnection.Release();
}
catch(_com_error& oE)
{
hr = ProcessError(&oE);
}
catch(...)
{
hr = ProcessConnectionError(spConnection);
}
return hr;
}
There are multiple tables that I read in. I connect, create a Recordset, iterate through the DB (reading the field values as I go along), close the Recordset, close the connection, and then repeat the process for all other tables. Each table that gets imported has it's own method.
The results are weird as well. The first table will come in fine with no errors or exceptions.
Usually it will hang in the DisconnectADO() method that gets called at the end of the ImportSecondDB() method. But sometimes an exception is thrown that gets caught in the
catch(...). I'm not really sure what's going on here and have already lost close to a week's worth of development time on this. I have provided some code "snipets" bellow. Any help, comments, or suggestions will be most welcomed and greatly appreciated.
HRESULT ClassName::Run()
{
HRESULT hr = S_OK;
for (int i=0; i<2; ++i)
{
switch(i)
{
case 0:
hr = ImportFirstDB();
break;
case 1:
hr = ImportSecondDB();
break;
default:
ASSERT(FALSE);
hr = E_FAIL;
}
}
}
HRESULT ClassName::ImportFirstDB()
{
ado::_ConnectionPtr spConnection;
ado::_RecordsetPtr spRecSet;
CString ostr;
HRESULT hr = S_OK;
_variant_t ovField;
try
{
if (SUCCEEDED(hr = ConnectADO(spConnection, spRecSet)))
{
if (SUCCEEDED(hr = spRecSet->Open(L"SELECT * FROM daily", _variant_t((IDispatch*)spConnection, true), ado::adOpenStatic,ado::adLockReadOnly, ado::adOptionUnspecified)))
{
if (SUCCEEDED(hr = spRecSet->MoveFirst()))
{
while(SUCCEEDED(hr) && !spRecSet->GetadoEOF())
{
ovField = spRecSet->GetCollect("col name");
if (ovField.vt != VT_NULL)
{
ostr = (_bstr_t)ovField;
}
hr = spRecSet->MoveNext();
}
}
}
}
}
catch(_com_error& oE)
{
hr = ProcessError(&oE);
}
catch(...)
{
hr = ProcessConnectionError(spConnection);
}
DisconnectADO(spConnection, spRecSet);
return hr;
}
HRESULT ClassName::ImportSecondDB()
{
ado::_ConnectionPtr spConnection;
ado::_RecordsetPtr spRecSet;
CString ostr;
HRESULT hr = S_OK;
_variant_t ovField;
try
{
if (SUCCEEDED(hr = ConnectADO(spConnection, spRecSet)))
{
if (SUCCEEDED(hr = spRecSet->Open(L"SELECT * FROM daily", _variant_t((IDispatch*)spConnection, true), ado::adOpenStatic,ado::adLockReadOnly, ado::adOptionUnspecified)))
{
if (SUCCEEDED(hr = spRecSet->MoveFirst()))
{
while(SUCCEEDED(hr) && !spRecSet->GetadoEOF())
{
ovField = spRecSet->GetCollect("col name");
if (ovField.vt != VT_NULL)
{
ostr = (_bstr_t)ovField;
}
hr = spRecSet->MoveNext();
}
}
}
}
}
catch(_com_error& oE)
{
hr = ProcessError(&oE);
}
catch(...)
{
hr = ProcessConnectionError(spConnection);
}
DisconnectADO(spConnection, spRecSet);
return hr;
}
HRESULT ClassName::ConnectADO(ado::_ConnectionPtr& spConnection, ado::_RecordsetPtr& spRecSet)
{
CString ostrConnection;
HRESULT hr = S_OK;
try
{
if (SUCCEEDED(hr = spConnection.CreateInstance(__uuidof(ado::Connection))))
{
ostrConnection = _T("Provider=VFPOLEDB.1;");
ostrConnection += _T("Data Source=");
ostrConnection += ostrInputFile + _T(";");
if (SUCCEEDED(hr = spConnection->Open(_bstr_t(ostrConnection), L"", L"", ado::adModeUnknown)))
{
spRecSet.CreateInstance(__uuidof(ado::Recordset));
spRecSet->CursorLocation = ado::adUseClient;
}
else
{
_com_issue_error(hr);
}
}
catch(_com_error &oE)
{
hr = ProcessError(&oE, _T("AccountView_WINTask::ConnectADO() - InputFile: ") + ostrInputFile);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
hr = E_FAIL;
}
return hr;
}
HRESULT ClassName::DisconnectADO(ado::_ConnectionPtr& spConnection, ado::_RecordsetPtr& spRecSet)
{
ASSERT(spConnection);
ASSERT(spRecSet);
HRESULT hr = S_OK;
try
{
if (spRecSet)
{
if (spRecSet->State == ado::adStateOpen)
{
hr = spRecSet->Close();
}
}
if (spConnection)
{
if (spConnection->State == ado::adStateOpen)
{
hr = spConnection->Close();
}
}
spRecSet.Release();
spConnection.Release();
}
catch(_com_error& oE)
{
hr = ProcessError(&oE);
}
catch(...)
{
hr = ProcessConnectionError(spConnection);
}
return hr;
}