我用ADO访问FOXPro数据库,数据源配置没有问题(因为在别的大多数机器上运行都没有任何问题),可是在有一台机器(Win2000 Professional)上运行时要么在此出错
_ConnectionPtr MyDb;
try{
 MyDb.CreateInstance(__uuidof(Connection));
 MyDb->Open("DSN=CliswClt_VF","","",0);
}
要么在下面出错
_RecordsetPtr MySet;
MySet.CreateInstance("ADODB.Recordset");
CString SqlStr="";
SqlStr.Format("SELECT * FROM dj01 WHERE a01 = '%s'",zdh);
try{
MySet->Open((_variant_t)SqlStr,
MyDb.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
出错时 catch(_com_error * e)
{
CString Error = e->ErrorMessage();
AfxMessageBox(e->ErrorMessage());
}语句都没有得到什么错误信息?
请问这是什么原因?谢谢(急)

解决方案 »

  1.   

    try dsnless connection string
    //=====================Open dbf database file
    #include "stdafx.h"
    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
    void PrintProviderError(ADODB::_ConnectionPtr pConnection);
    int main(int argc, char* argv[])
    {
    printf("Use ADO to open c:\\tmp\\images.dbf database file!\n");
       CoInitialize(NULL);
       try
       {
          _ConnectionPtr pConn("ADODB.Connection");
          _RecordsetPtr  pRst("ADODB.Recordset");
    pConn->Open("Driver={Microsoft dBASE Driver (*.dbf)};DBQ=C:\\tmp\\; DriverID=533;"
    ,"","",adConnectUnspecified);
          pRst->Open("images", _variant_t((IDispatch *) pConn, true),
             adOpenStatic, adLockReadOnly, adCmdTable);
      FieldsPtr fds=pRst->GetFields();
      printf("printf field name of all the table\n");
      for(int i=0;i<fds->GetCount();i++)
      {
      FieldPtr fd=fds->GetItem(_variant_t(short(i)));
      printf("%s   ",(LPCTSTR)fd->GetName());
      }
      printf("\n");
          pRst->Close();
          pConn->Close();
       }
    catch(_com_error &e)
    {
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    printf("\nCOM error occurred, Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    PrintProviderError(pConn);
    }
    ::CoUninitialize();
    return 0;
    }
    VOID PrintProviderError(ADODB::_ConnectionPtr pConnection)
    {
      // Print Provider Errors from Connection object.
      // pErr is a record object in the Connection's Error collection.
            ADODB::ErrorPtr  pErr = NULL;
      long      nCount = 0;
      long      i = 0;  if( (pConnection->Errors->Count) > 0)
      {
          nCount = pConnection->Errors->Count;
          // Collection ranges from 0 to nCount -1.
          for(i = 0; i < nCount; i++)
          {
            pErr = pConnection->Errors->GetItem(i);
            printf("\n\t Error number: %x\t%s", pErr->Number, (LPCSTR)pErr->Description);
          }
      }
    }