I have a SqlCommand that I want to call Prepare() on whose CommandType = Text (it cannot be a stored procedure).
In order to do this, I need to set the Size attribute on the parameters to be non-zero otherwise an exception is thrown. Are there any negative effects from setting the Size on all parameters to the maximum possible size even if the size of the actual values will never come close to that? Is there a better way to do this?
I think the only potential negative side effect of doing something like that would be the cost of memory allocation for the parameters.
Since you’re calling ‘Prepare()’ I’m guessing you’re planning to use the SqlCommand multiple times against the same SqlConnection which suggests a discrete section of code where it’s likely to be used (if the connection closes for a prepared command, the command text will have to be re-transmitted to the server on the next usage).
If you know the nature of your parameters, it seems like you might have some idea about their potential sizes. If not, then I don’t see what alternative you have, really, than to declare a significantly large size for each – large enough to hold most/any potential values.