Skip to content
Advertisement

EF6 Stored Procedure does not accept parameters

I am using EF6 and I need to execute stored procedure. It takes two parameters:

  • mIIN varchar(12), which is input string
  • mXMLOutput varchar(max), which is the result of execution

It works fine when I call it from Management Studio.

However, when I use the following code:

var iinParameter = new SqlParameter("@mIIN", SqlDbType.VarChar, 12) { Value = "123456123456" };
var outputParameter = new SqlParameter("@mXMLContent", SqlDbType.VarChar, -1) { Direction = ParameterDirection.Output };
_dbContext.Database.ExecuteSqlCommand("GetInfo", iinParameter, outputParameter);

which results in the error

Procedure or function ‘GetInfo’ expects parameter ‘@mIIN’, which was not supplied

EF6 contains the following messages:

Started transaction at 15.12.2015 14:27:27 +06:00  
GetInfo  
-- @mIIN: '123456123456' (Type = AnsiString, IsNullable = false, Size = 12)   
-- @mXMLContent: '' (Type = AnsiString, Direction = Output, IsNullable = false, Size = -1)  
-- Executing at 15.12.2015 14:27:27 +06:00  
-- Failed in 2 ms with error: Procedure or function 'GetInfo' expects parameter '@mIIN', which was not supplied.

What can cause that problem? I am passing this parameter, why doesn’t it accept it?

Advertisement

Answer

This should work:

_dbContext.Database.ExecuteSqlCommand("exec GetInfo @mIIN, @mXMLContent OUTPUT", iinParameter, outputParameter);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement