PDA

View Full Version : Stored Procedure that returns no resultset but sets an out parameter


Flozano
04-19-2007, 12:18 PM
In SQL Server 2005, when I try to exec a Stored Procedure which doesn't return any rowset but sets an output parameter, I get the following exception:

System.ArgumentNullException:
Argument 'namedResultSetProcessors' cannot be null or resolve to an empty array
Parameter name: namedResultSetProcessors


I've defined a SQL Server 2005 SP like this:


CREATE PROCEDURE [dbo].[voice_call_insert]
(
@voice_call_id int = NULL OUTPUT,
@calling_number varchar(20),
@called_number varchar(30),
@call_duration int,
@started_at datetime,
@route_quality_id varchar(50),
@routing_table_id varchar(50),
@tdm_switch_id varchar(50)
)
AS
SET NOCOUNT ON

INSERT INTO [voice_call]
(
[calling_number],
[called_number],
[call_duration],
[started_at],
[route_quality_id],
[routing_table_id],
[tdm_switch_id]
)
VALUES
(
@calling_number,
@called_number,
@call_duration,
@started_at,
@route_quality_id,
@routing_table_id,
@tdm_switch_id
)

SELECT @voice_call_id = SCOPE_IDENTITY();

RETURN @@Error


I've also created a class that inherits from StoredProcedure:

class VoiceCallInsert : StoredProcedure
{
protected static string storedProcedureName = "dbo.voice_call_insert";
public VoiceCallInsert(IDbProvider dbProvider)
: base(dbProvider, storedProcedureName)
{
DeriveParameters();
Compile();
}

protected System.Collections.IDictionary ToDict(VoiceCallMessage message)
{
System.Collections.IDictionary paramz = new System.Collections.Hashtable(7);
paramz.Add("@calling_number", message.CallingNumber);
paramz.Add("@called_number", message.CalledNumber);
paramz.Add("@call_duration", message.CallDuration);
paramz.Add("@started_at", message.StartedAt);
paramz.Add("@route_quality_id", message.RouteQualityId);
paramz.Add("@routing_table_id", message.RoutingTableId);
paramz.Add("@tdm_switch_id", message.TdmSwitchId);
return paramz;
}

public virtual int Run(VoiceCallMessage message)
{
System.Collections.IDictionary result = QueryByNamedParam(ToDict(message));
int voiceCallId = (int)result["@voice_call_id"];
return voiceCallId;
}
}

Flozano
04-27-2007, 06:03 PM
Noone knows anything about this one? :(

Mark Pollack
05-01-2007, 01:51 AM
Hi,

Sorry for the delay. I reproduced your test case and fixed the bug. See SPRNET-543 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-543) for more info. You can get the latest build, May 1st, and give it a try.

Cheers,
Mark

Flozano
05-02-2007, 08:44 PM
Thankx! :D