Size property has an invalid size of 0
Solution 1
You need to define a length when specifying the varchar
parameter:
SqlParameter job1 = cmd2.Parameters.Add("@job", SqlDbType.VarChar, 50);
You should use the same length as defined in your SQL Server stored procedure.
And btw: if your stored procedure also has no length defined (something like @job VARCHAR OUTPUT
) - then you've defined a varchar
string of 1 character length ......
Solution 2
If you are using Dapper, you have passed in a null value for the parameter, where the expected input was a string.
To find the offending value and it's parameter, inspect at the Dapper DynamicParameters object during a debug session and open the parameters being index referred to.
RuMoR
Updated on November 27, 2020Comments
-
RuMoR over 3 years
I am working on a social network, one of my procedures returns a VARCHAR output. So this is what I wrote:
SqlParameter job1 = cmd2.Parameters.Add("@job", SqlDbType.VarChar); job1.Direction = ParameterDirection.Output;
However this error comes up:
String[1]: the Size property has an invalid size of 0.
-
Chillin' about 5 yearsI have a question because I have the same exception...if the column is varchar, what is the danger of having varchar in your SP and code using DbType.AnsiString
-
thalacker over 4 yearsIt is known as the "Size" attribute in case you need to specify it like I did