这是别人给我的存储过程,ORACLE817的,WIN2K平台下
(
idname in varchar2,id out integer)
as
row_count integer;
begin
  lock table t_identity in row exclusive mode;
  update t_identity
      set maxno=maxno + 1
      where name=idname;
   select maxno into id from t_identity where name=idname;
  commit;
end;
这是我调用存储过程的函数,返回值是ID值,但是再*****那一行出错
int GetNewID(char *Inputstr)
{
int ret=-1; //调用带输入和输出参数的存储过程
_CommandPtr cmd;
cmd.CreateInstance("ADODB.Command");

//输入参数
_ParameterPtr pParamRk;
pParamRk.CreateInstance("ADODB.Parameter"); //pParamRk->Name="mo07"; //存储过程的参数1
pParamRk->Type=adChar; //字符串
pParamRk->Size=20;
pParamRk->Direction=adParamInput;//表明是输入参数
pParamRk->Value=_variant_t(Inputstr);//int->CString->_variant_t后赋值
//****************************************
cmd->Parameters->Append(pParamRk);//此句执行出错????????
//****************************************

//输出参数
_ParameterPtr pParamOk;
pParamOk.CreateInstance("ADODB.Parameter");
//pParamOk->Name="rowcount"; //参数2名称
pParamOk->Type=adInteger; //整型
pParamOk->Direction=adParamOutput; //声明是输出参数
cmd->Parameters->Append(pParamOk);

cmd->ActiveConnection = m_pConnection;
cmd->CommandText="ADE.PROC_ALLOC_ID"; //存储过程的名字
cmd->CommandType=adCmdStoredProc;//表示为存储过程adCmdStoredProc
 
//执行,获得结果
_RecordsetPtr m_pRecordset;
    m_pRecordset = cmd->Execute(NULL, NULL, adCmdStoredProc);
printf("storeproc id is:%s\n",(char*)_bstr_t(pParamOk->Value));
//AfxMessageBox((char*)_bstr_t(pParamRk->Value));
//AfxMessageBox((char*)_bstr_t(pParamOk->Value));
ret=atoi((char*)_bstr_t(pParamOk->Value)); return ret;
}出的错是Debug error!

解决方案 »

  1.   

    是GPE还是断言还是编译不过?给出出错信息看一下。
      

  2.   

    因为不能在服务器上调试,只能编译好了多打些打印信息找错误,执行到cmd->ActiveConnection = m_pConnection;跳出
    catch说是无效指针。但是,我编写的这个函数在我自己的机器上怎么运行都正常啊!!!感谢各位的帮助,如果各位给我提供的办法尝试成功,800分绝对少不了,再次谢谢各位!
      

  3.   

    是在
    cmd->Parameters->Append(pParamRk);
    还是在
    cmd->ActiveConnection = m_pConnection
    执行出错???提供出错信息啊
      

  4.   

    This code show you how to use the sql string in ADO  ,but I think the stored procedure mechanism is same as SQL .
    void SourceX(void) 
    {
        HRESULT  hr = S_OK;    // Define string variables.
        _bstr_t strCmdSQL("Select title,type,pubdate "
            "FROM titles ORDER BY title");  
        _bstr_t strSQL("SELECT title_ID AS TitleID, title AS Title, " 
            "publishers.pub_id AS PubID, pub_name AS PubName "
            "FROM publishers INNER JOIN titles " 
            "ON publishers.pub_id = titles.pub_id " 
            "ORDER BY Title");
        _bstr_t strCnn("Provider='sqloledb';Data Source='MySqlServer';"
            "Initial Catalog='pubs';Integrated Security='SSPI';");    // Define ADO object pointers.
        // Initialize pointers on define.
        // These are in the ADODB::  namespace.
        _ConnectionPtr  pConnection          = NULL;
        _RecordsetPtr  pRstTitles        = NULL;
        _RecordsetPtr  pRstPublishers      = NULL;
        _RecordsetPtr  pRstPublishersDirect    = NULL;
        _RecordsetPtr  pRstTitlesPublishers    = NULL;
        _CommandPtr     pCmdSQL          = NULL;    try
        {
            // Open a connection.
            TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
            pConnection->Open (strCnn, "", "", adConnectUnspecified);        // Open a recordset based on a command object.
            TESTHR(pCmdSQL.CreateInstance(__uuidof(Command)));
            pCmdSQL->ActiveConnection = pConnection;
            pCmdSQL->CommandText = strCmdSQL;
            pRstTitles = pCmdSQL->Execute(NULL,NULL,adCmdText);        // Open a recordset based on a a table
            TESTHR(pRstPublishers.CreateInstance(__uuidof(Recordset)));
            pRstPublishers->Open ("publishers", 
                _variant_t((IDispatch *) pConnection, true),
                adOpenForwardOnly, adLockReadOnly, adCmdTable);        // Open a recordset based on a table
            TESTHR(pRstPublishersDirect.CreateInstance(
                __uuidof(Recordset)));
            pRstPublishersDirect->Open ("publishers", 
                _variant_t((IDispatch *) pConnection, true),
                adOpenForwardOnly, adLockReadOnly, adCmdTableDirect);        // Open a recordset based on a SQL string.
            TESTHR(pRstTitlesPublishers.CreateInstance(
                __uuidof(Recordset)));
            pRstTitlesPublishers->Open(strSQL, 
                _variant_t((IDispatch *) pConnection, true),
                adOpenForwardOnly, adLockReadOnly, adCmdText);        // Use the Source property to display the source of 
            // each recordset.
            printf("rstTitles source: \n%s\n\n",
                (LPCSTR)(_bstr_t) pRstTitles->GetSource().bstrVal);
            printf("rstPublishers source: \n%s\n\n",
                (LPCSTR)(_bstr_t) pRstPublishers->GetSource().bstrVal);
            printf("rstPublishersDirect source: \n%s\n\n",
                (LPCSTR)(_bstr_t) pRstPublishersDirect->GetSource().bstrVal);
            printf("rstTitlesPublishers source: \n%s\n\n",
                (LPCSTR)(_bstr_t) pRstTitlesPublishers->GetSource().bstrVal);
        }
        catch (_com_error &e)
        {
            // Notify the user of errors if any.
            PrintProviderError(pConnection);
            PrintComError(e);
        }    if (pRstTitles)
            if (pRstTitles->State == adStateOpen)
                pRstTitles->Close();
        if (pRstPublishers)
            if (pRstPublishers->State == adStateOpen)
                pRstPublishers->Close();
        if (pRstPublishersDirect)
            if (pRstPublishersDirect->State == adStateOpen)
                pRstPublishersDirect->Close();
        if (pRstTitlesPublishers)
            if (pRstTitlesPublishers->State == adStateOpen)
                pRstTitlesPublishers->Close();
        if (pConnection)
            if (pConnection->State == adStateOpen)
                pConnection->Close();
    }
      

  5.   

    Doese the ADO istance created correctly ? You must assure the ADO instance is created correctlly .
        //Define ADODB object pointers.
        ADODB::_ConnectionPtr m_pCnn = NULL;
        ADODB::_CommandPtr m_pCommand = NULL;
        ADODB::_ParameterPtr m_pParameter = NULL;    try 
        {
            hr = m_pCnn.CreateInstance(__uuidof(ADODB::Connection));
            ASSERT(hr);
            
        } catch (com_error &e) {
           MesssageBox ("YOu Message ErrMsg","");    }
      

  6.   

    The Connection and Parameters and Command instance ceate by using CreateInstance with ADO data type .