1

Actual Stored Procedure is

ALTER Procedure [dbo].[ApplyList] 
    @oldlist int, @username varchar(50),
    @newlist int, @errormessage varchar(2000) output
AS
BEGIN
    SET NOCOUNT ON;
    SET @errormessage = '';
END

Here is the SQL code generated by Entity Framework 6.1 and using Database First approach.

declare @p6 varchar(2000);
set @p6=NULL;
exec sp_executesql N'EXEC [dbo].[ApplyList] {0}, {1}, {2}, {3}',N'@oldlist int,@username nvarchar(50), @newlist int,@errormessage varchar(2000) output',@oldlist='20',@username=N'mk',@newlist='18',@errormessage=@p6 output
select @p6

Why I'm getting the message "Incorrect syntax near '0'." while I'm trying to execute the above query in Management Studio.

This is working if I call in the below format from Management Studio.

DECLARE @P6 nvarchar(2000)
set @P6 = null
exec ApplyList '20', 'mk', '18', @p6 output
select @p6
go
manu97
  • 7,237
  • 2
  • 17
  • 21

1 Answers1

0

In SSMS (T-SQL) you cannot use parameter place-holders, you need to state them explicitly:

exec sp_executesql 
    N'EXEC [dbo].[ApplyList] @oldlist, @username, @newlist, @errormessage output',
    N'@oldlist int,@username nvarchar(50), @newlist int,@errormessage varchar(2000) output',
    @oldlist='20',@username=N'mk',@newlist='18',@errormessage=@p6 output
select @p6
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • Thank you. While reviewing the .net code found that I was constructing the parameter place holders for different case which was working fine in the application. I need to fix the the code to pass the names explicitly. – manu97 Sep 29 '15 at 16:54