OLE DB Bind()在插入行时调用Assert

时间:2010-11-16 15:46:35

标签: sql-server binding oledb assert

我正在尝试使用Ole DB将数据插入到MS SQL Server 2008中。我的插入程序是:

ALTER PROCEDURE [dbo].[table_insert]
@category as bigint
AS
BEGIN
    INSERT INTO dbo.table
    (category)
    VALUES(@category)


    SELECT SCOPE_IDENTITY() as id;
END 

当我调用该程序时,它会正确执行。插入新行。我使用访问器获取新的行ID:

class DCCRetValueAccessor
{
public:
    __int64 id;

BEGIN_COLUMN_MAP(DCCRetValueAccessor)
    COLUMN_ENTRY(1, id)
END_COLUMN_MAP()

    void ClearRecord()
    {
        memset(this, 0, sizeof(*this));
    }
};

要执行该过程并获取新的行ID,我使用以下代码:

    CString cmd;
    __int64 newID = -1;

    cmd.Format(_T("EXEC [dbo].[alert_settings_insert] @category=%I64d"), value->category);

    CCommand<CAccessor<DCCRetValueAccessor>> command;

    if(DC_SUCCEEDED(command.Open(m_session, cmd)))
    {
        if(command.MoveFirst() == S_OK)
        {
        newID = command.id;

        }
        else
            return -1;
    }
    else
    {
        LogError();
        return -1;
    }
    return newID;

问题是,在atldbcli.h中调用GetInterface()后,我在方法Bind()中得到了ASSERT错误,Line:6108,expression:GetInterface()!= 0.

我看不出错误。你能帮我吗? 感谢

1 个答案:

答案 0 :(得分:0)

解决方案是添加 SET NOCOUNT ON ;这样的程序:

ALTER PROCEDURE [dbo].[table_insert]
@category as bigint
AS
BEGIN
  INSERT INTO dbo.table
  (category)
  VALUES(@category)


  SELECT SCOPE_IDENTITY() as id;
END