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!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: