Q:

Executing Sp_SetAppRole from ExecuteSqlCommand

Here is my Code:
            SqlParameter rolename = new SqlParameter("rolename", SqlDbType.VarChar);
            rolename.Direction = ParameterDirection.Input;
            rolename.Value = "role";                

            SqlParameter password = new SqlParameter("password", SqlDbType.VarChar);
            password.Direction = ParameterDirection.Input;
            password.Value = "123@123";

            SqlParameter fCreateCookie = new SqlParameter("fCreateCookie", SqlDbType.Bit);
            fCreateCookie.Direction = ParameterDirection.Input;
            fCreateCookie.Size = 100;
            fCreateCookie.Value = true;                

            SqlParameter cookie = new SqlParameter("cookie", SqlDbType.VarBinary);
            cookie.Direction = ParameterDirection.Output;
            cookie.Size = 8000;

            _context.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "EXEC sp_setapprole @rolename,@password,@fCreateCookie, @cookie OUT;", rolename, password, fCreateCookie, cookie);

And I am getting an Error:
The formal parameter "@fCreateCookie" was not declared as an OUTPUT parameter, but the actual parameter passed in requested output.
Can someone tell me what I am doing wrong?

A:

you are missing a parameter 
    ALTER procedure [sys].[sp_setapprole]
        @rolename   sysname,        -- name app role
        @password   sysname,        -- password for app role
-->     @encrypt    varchar(10) = 'none',       -- Encryption style ('none' | 'odbc')
        @fCreateCookie bit = 0,  
        @cookie varbinary(8000) = 0xFFFFFFFF OUTPUT
    as

you need to add a paramerer @encrypt = 'none'  before @fcreatecookie in your executesqlcommand call

