Skip to content
Advertisement

Too many arguments passed to Stored Procedure storing image

I am trying to store a JPG image into a MSSQL Server 2014. The image path was being passed into a stored procedure and part of the process within the proc is to store the image into a VARBINARY(MAX) field (I cannot change schema). My first attempt was within the same proc like this:

Even though the command that came from the PRINT() statement executed as expected I ran into problems executing it within the stored proc. It was a VARCHAR conversion error that nearly caused the laptop to take a flying lesson, but part of the research I was doing suggested breaking this bit out into a separate stored procedure. Without really understanding the logic of the reasoning and in desperation I followed this path. Same problem.

Then I changed the stored proc to accept the binary data and pass it in via a calling app. I based it on this.

(stripped down version)

It is called from another SP like this:

Have also tried unnamed params:

No matter what I try I get the same error:

Procedure or function usp_InsertImage has too many arguments specified.

I have got to a point where I am not so sure I am even approaching this is the right way, it seems way more irritating than it should be. Either that or I am being a total plank and missing something obvious, its a 50/50 chance.

This is just dev code but can someone tell me if this approach is correct?

Advertisement

Answer

The error message suggests that you are connected to a different database (or different instance) where the definition of the procedure hasn’t been updated. Please check your connection strings (and make sure nothing you’re using is doing anything like AttachDbFileName – which means it is using its own, different copy of the database file). See this and this for more details.

You can confirm your calling code is not connecting to a different database by:

  • changing the procedure definition to have too many required arguments, and see if the error message changes.
  • change the name of the procedure, and see if your existing code still finds it.
  • create a copy of the procedure, with a different name, and change your code to see if it finds the new object.
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement