Search This Blog

Wednesday, January 20, 2016

ado.net error : String[2]: the Size property has an invalid size of 0

I am getting below error while executing stored procedure from C# (Ado.net, entity framework)

String[2]: the Size property has an invalid size of 0.

SqlParameter input1Parameter = new SqlParameter()
            {
                ParameterName = " input1",
                Direction = System.Data.ParameterDirection.Input,
                Value = input1,
                SqlDbType = System.Data.SqlDbType.VarChar
            };
SqlParameter input2Parameter = new SqlParameter()
            {
                ParameterName = " input2",
                Direction = System.Data.ParameterDirection.Input,
                Value = input2,
                SqlDbType = System.Data.SqlDbType.VarChar
            };
SqlParameter output1Parameter = new SqlParameter()
            {
                ParameterName = "output1",
                Direction = System.Data.ParameterDirection.Output,
                SqlDbType = System.Data.SqlDbType.VarChar
            };
Old query: throwing error as “String[2]: the Size property has an invalid size of 0
var result = Database.ExecuteSqlCommand("exec schemaname.stored_proc_name @input1, @input2, @output1 OUTPUT", input1Parameter, input2Parameter, output1Parameter);

Updated Query: Fix : removed exec

var result = Database.ExecuteSqlCommand("schemaname.stored_proc_name @input1, @input2, @output1 OUTPUT", input1Parameter, input2Parameter, output1Parameter);

Popular Posts