I have a query that should always be returning a single int. I have now logged it returning a string entirely unrelated to what it should be.
We\'ve been ge
I've recently seen a case where code was switching connection strings unexpectedly. For diagnostic purposes, please hard code the connection string and see if the problem goes away.
Also, for sanity's sake, please use nested using blocks like:
using(SqlConnection conn = new SqlConnection("hard-coded connection string"))
{
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
// more init
object scalar = cmd.ExecuteScalar();
// process result
}
}
It wouldn't surprise me to find there are two database instances, and in one, PkID is an int, in another it's varchar.
Take a look with SQL Profiler to see if you can catch the return of "gladiator". In the other case I was working with, SQL Profiler showed nothing at all, indicating that the actual query was going to a different database.