Solution to SqlCommand "expects parameter" Exception
I was getting this exception earlier today: Test method x threw exception: System.Data.SqlClient.SqlException: Procedure or function ‘sp_get_x’ expects parameter ‘@x’, which was not supplied…
I was 100% certain that the parameter was there, so I ran a SQL profile and noticed it was treating the cmd as plain text.
Turns out that I forgot to set the CommandType property to StoredProcedure.
List profileContacts = null;
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
using (SqlCommand cmd = new SqlCommand("sp_get_x", conn))
using (DataSet ds = new DataSet())
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))