I have inherited code that I am fixing security holes up. What's the best practice for handling SQL injections when a stored procedure is called?
The code is something like:
StringBuilder sql = new StringBuilder("");
sql.Append(string.Format("Sp_MyStoredProc '{0}', {1}, {2}", sessionid, myVar, "0"));
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Main"].ToString()))
{
cn.Open();
using (SqlCommand command = new SqlCommand(sql.ToString(), cn))
{
command.CommandType = CommandType.Text;
command.CommandTimeout = 10000;
returnCode = (string)command.ExecuteScalar();
}
}
I just do the same thing with a regular SQL query and add the parameters using AddParameter correct?