PRB: SQL Server Stored Procedure's Out Parameters Can Return Incorrect ValuesID: Q224591
|
When using ADO and the default server side cursor is out, parameters return NULL values.
ADO doesn't fill in the out parameters for a recordset created using adUseServer (server side cursor) until the returned recordset is closed.
Use one of the following methods to get the correct output values from the stored procedure.
conn->CursorLocation=adUseClient;
rs->Close();
This behavior is by design.
if exists (select * from sysobjects where id = object_id(N'[dbo].[GetJobs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop proc GetJobs
go
create proc GetJobs @id as int, @count as int [out] as
begin
Select @count = Count(*) from jobs where job_id >@id
Select * from jobs where job_id >@id
end
go
#include "stdafx.h"
#include "stdio.h"
#import "C:\PROGRA~1\COMMON~1\System\ado\msado15.dll" no_namespace rename ("EOF", "EOF2")
struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_;
int main(int argc, char* argv[])
{
_variant_t varErr((long)0, VT_ERROR);
_CommandPtr comm(__uuidof(Command));
_ConnectionPtr conn(__uuidof(Connection));
_bstr_t connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)";
conn->Open(connstr, "", "", adConnectUnspecified);
comm->ActiveConnection=conn;
comm->CommandText="GetJobs";
comm->CommandType = adCmdStoredProc ;
comm->Parameters->Refresh();
_variant_t recs;
comm->Parameters->Item[_variant_t((short)1)]->Value= _variant_t((long)5);
_RecordsetPtr rs = comm->Execute(&recs, &vtMissing,adCmdStoredProc);
_variant_t recordcount= comm->Parameters->Item[_variant_t((short)2)]->Value;
printf("recordcount = %li\n", (long)recordcount);
return 0;
}
Additional query words:
Keywords : kbADO kbDatabase kbVC kbGrpVCDB
Version : WINDOWS:1.5,2.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 30, 1999