存储过程没有问题。因为在一台机器上已经通过了。
存储过程是dbo的,两台机器上都是用sa访问。
对了,此时刚刚才CreateInstance,还没有跟SQL SERVER发生任何关系阿!

解决方案 »

  1.   


    void dump_com_error(_com_error &e)
       {
    printf("Error\n");
    printf("\a\tCode = %08lx\n", e.Error());
    printf("\a\tCode meaning = %s", e.ErrorMessage());
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    printf("\a\tSource = %s\n", (LPCSTR) bstrSource);
    printf("\a\tDescription = %s\n", (LPCSTR) bstrDescription);
       }
    int main(int argc, char* argv[])
    {
    printf("Hello World!\n");
    ::CoInitialize(NULL); 
    try 
          { _ConnectionPtr pCon=NULL;
    _RecordsetPtr    pRs=NULL;

    pCon.CreateInstance(__uuidof(Connection)); 
    pCon->Open("Export","dongsong","dongsong",adConnectUnspecified); 

    pRs.CreateInstance(__uuidof(Recordset));
    pRs->CursorLocation=adUseClient; 
    pRs->Open("select name from sysobjects where type='u'",
    _variant_t((IDispatch *) pCon, true),adOpenStatic, adLockReadOnly, adCmdUnknown);
       while (!(pRs->EndOfFile))
       {
        
    printf("%s\n",(char*)_bstr_t(pRs->Fields->Item["name"]->Value));

    pRs->MoveNext();
       }
    }catch (_com_error &e)
          {
          dump_com_error(e);
          }
    ::CoUninitialize();
    return 0;
    }
      

  2.   

    CreateInstance不会抛出异常。只返回错误。