Search code examples
sql-serverbindingoledbassert

OLE DB Bind() Invoke Assert on inserting rows


I am trying to insert data into MS SQL server 2008 using Ole DB. my insert procedure is:

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


    SELECT SCOPE_IDENTITY() as id;
END 

When I call the procedure, it is executed properly. New row is inserted. I use accessor to get new row id:

class DCCRetValueAccessor
{
public:
    __int64 id;

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

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

To execute the procedure and get new row id I use this code:

    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;

Problem is, that I get ASSERT error in method Bind() after calling GetInterface() in atldbcli.h, Line:6108, expression: GetInterface() != 0.

I cannot see the error. Can you help me please? Thanks


Solution

  • the solution is to add SET NOCOUNT ON; to the procedure like this:

    ALTER PROCEDURE [dbo].[table_insert]
    @category as bigint
    AS
    BEGIN
      INSERT INTO dbo.table
      (category)
      VALUES(@category)
    
    
      SELECT SCOPE_IDENTITY() as id;
    END