Hey guys,
I have an app that's been deployed a while and today I get some complaint that it's crashing. So I go and investigate and narrow down the problem to a single quote that is finding it's way into a sql query.
This perplexes me as I use parameterized stored procedures for every query in the program. I always thought that if you use parameters, then all special characters are escaped automatically. Not so it seems, despite numerous google searchs claiming otherwise.
I add my parameters like this...
C.Parameters.AddWithValue("@TRXDATE", TrxnDate); C.Parameters.AddWithValue("@CURNCYID", currency);
...
and execute like so...
lock(m_QueryPadlock) {
jrnEntry = Convert.ToInt32(C.ExecuteScalar());
}
The exception message is:
Incorrect syntax near 'd'. Unclosed quotation mark after the character string ')'.
The string that caused the problem is: "March-Funds Rec'd"
What gives???
I have an app that's been deployed a while and today I get some complaint that it's crashing. So I go and investigate and narrow down the problem to a single quote that is finding it's way into a sql query.
This perplexes me as I use parameterized stored procedures for every query in the program. I always thought that if you use parameters, then all special characters are escaped automatically. Not so it seems, despite numerous google searchs claiming otherwise.
I add my parameters like this...
C.Parameters.AddWithValue("@TRXDATE", TrxnDate); C.Parameters.AddWithValue("@CURNCYID", currency);
...
and execute like so...
lock(m_QueryPadlock) {
jrnEntry = Convert.ToInt32(C.ExecuteScalar());
}
The exception message is:
Incorrect syntax near 'd'. Unclosed quotation mark after the character string ')'.
The string that caused the problem is: "March-Funds Rec'd"
What gives???