Yeldar Kurmangaliyev
Yeldar Kurmangaliyev

Reputation: 34199

EF6 Stored Procedure does not accept parameters

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

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?

Upvotes: 0

Views: 210

Answers (3)

Umar Faruq
Umar Faruq

Reputation: 1

There are few things that are must to call a stored procedure using EF 6.

  1. Provide all parameters including optional parameters
  2. Define parameter values as SqlParameter
  3. Provide all values as string in SqlParameter constructor

Upvotes: 0

strickt01
strickt01

Reputation: 4048

This should work:

_dbContext.Database.ExecuteSqlCommand("exec GetInfo @mIIN, @mXMLContent OUTPUT", iinParameter, outputParameter);

Upvotes: 2

Sławomir Pawluk
Sławomir Pawluk

Reputation: 106

I think that problem is in your subprocedure. Log message tells that parameter was suplied to GetInfo, and error is related to subprocedure IBRC_GetClientInfo. Check your procedure that parameter inside is properly passed.

Upvotes: 0

Related Questions