Sue Hernandez's SharePoint Blog

SharePoint and Related Stuff

Stupid Mistake – stored procedure expects parameter which was not supplied

I made a boneheaded mistake today and wanted to write it down so I don’t make the same boneheaded mistake again.

I was writing a program for gathering some custom metrics in SharePoint, to be stored in a custom SQL table.   I had written a stored procedure and properly passed in all parameters, or so I thought.

SqlCommand cmd = new SqlCommand("NameOfMyStoredProcedure", mainConnectionObj);

cmd.Parameters.Add(new SqlParameter("@TimeStamp", startTime));
cmd.Parameters.Add(new SqlParameter("@WebURL", web.Url));
... [more parameters here]

I kept getting “Stored Procedure NameOfMyStoredProcedure expects parameter @TimeStamp which was not supplied”.  I double-checked and triple-checked to make sure I had the syntax right.  I then went down the route of thinking that TimeStamp was a reserved word.  But then I tried something – I reversed my first 2 parameters, and sure enough, it was complaining about @WebURL this time.

Turns out it was extremely simple.  I just needed to specify the CommandType, telling it that it was indeed a stored procedure.

SqlCommand cmd = new SqlCommand("NameOfMyStoredProcedure", mainConnectionObj);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@TimeStamp", startTime));
cmd.Parameters.Add(new SqlParameter("@WebURL", web.Url));

That was it. It then worked like a charm!

Leave a comment