Does ADO.NET sanitize wildcards (i.e. "%" or "_") in string-type SqlParameters? Furthermore, does it need to? I've tried Googling for this, but it's hard to find exactly what I want to know.
For example, suppose I have a parameterized query:
string sql = "SELECT * FROM Users WHERE UserName LIKE @prefix";
SqlCommand command = new SqlCommand(sql, connection);
command.Parameters.AddWithValue("prefix", User.UserName);
//etc...
But the user somehow manages to get himself a username like %
. His idea is that he'll see all users, not just the ones he was supposed to see. Will this work, or would the %
get a) escaped when the value is parameterized, or b) evaluated as a literal %
by the SQL server?
Note that I realize the above would be a really lousy design. It's just a made-up example.
Edit: I've confirmed by testing that option b) doesn't happen.
declare @prefix as varchar(10);
set @prefix = '%';
select * from MyTable where MyField like @prefix;
--returns everything