J
Jerad Rose
I believe this question is simple enough -- why aren't data types in
SqlParameters validated in ADO.NET?
For example, why is an exception *not* thrown on this line:
cmd.Parameters.Add(New SqlParameter("@Id", Data.SqlDbType.Int)).Value = "not
an int"
Ideally, this wouldn't even compile, let alone execute. But it's even worse
that this line will execute, only later to bomb out when the stored proc is
executed, giving me this error:
Failed to convert parameter value from a String to a Int32.
Which can lead you on a wild goose chase tracking down the one out of
possibly several parameters that had a type issue.
My next question is, if the data type parameter in this constructor is not
for the sake of type safety, what is its purpose?
Lastly, is there anything that can be done (within reason) to ensure type
safety when setting parameter values, so that an exeption is thrown on the
line where the parameter value was attempted to be set? If not, what is the
best practice for accomplishing type safety when setting up store procedures
in ADO.NET?
Just FYI, this is in reference to ADO.NET 2.0.
Thanks in advance for your feedback.
Jerad
SqlParameters validated in ADO.NET?
For example, why is an exception *not* thrown on this line:
cmd.Parameters.Add(New SqlParameter("@Id", Data.SqlDbType.Int)).Value = "not
an int"
Ideally, this wouldn't even compile, let alone execute. But it's even worse
that this line will execute, only later to bomb out when the stored proc is
executed, giving me this error:
Failed to convert parameter value from a String to a Int32.
Which can lead you on a wild goose chase tracking down the one out of
possibly several parameters that had a type issue.
My next question is, if the data type parameter in this constructor is not
for the sake of type safety, what is its purpose?
Lastly, is there anything that can be done (within reason) to ensure type
safety when setting parameter values, so that an exeption is thrown on the
line where the parameter value was attempted to be set? If not, what is the
best practice for accomplishing type safety when setting up store procedures
in ADO.NET?
Just FYI, this is in reference to ADO.NET 2.0.
Thanks in advance for your feedback.
Jerad