views:

1246

answers:

4

I'm getting the following error when calling a stored procedure:

Cannot find the object "XXX" because it does not exist or you do not have permission.

I've checked the database and the SP is there with the correct permissions yet I'm still getting the error.

Any suggestions?

+1  A: 

The account that you are using when calling the stored procedure must not be the same account that you are using to check it. Make sure that the account that you are using to execute the sproc has access to the object.

Andrew Hare
The web application is impersonating a domain user which has access to the stored proc. This is the case for all other stored proc used in the system (in excess 250 others). And only this one is giving the problem. I've tried to re-assign the permissions without success.
Twiggz
A: 

Always use the dbo. (or other schema) prefix both when creating and when accessing objects.

I wrote about this very topic recently:

http://sqlblog.com/blogs/aaron%5Fbertrand/archive/2009/10/11/bad-habits-to-kick-avoiding-the-schema-prefix.aspx

Aaron Bertrand
The stored proc was created with the dbo schema prefix and I'm accessing it through Microsoft Application Block, does this count?
Twiggz
Sorry, I don't know what a "Microsoft Application Block" is. Is there any way to tell it to call "dbo.ProcedureName" instead of just "ProcedureName"?
Aaron Bertrand
A: 

As well as other answers about schema/security etc:

  • do you have a DENY on it somewhere?
  • case sensitive object names and using "wrong" name?
  • wrong database context? eg OtherDB.dbo.Myproc
gbn
A: 

Ok, here's what happened. There was a special character before the end of the SP so it was incomplete yet still valid, somehow.

So I could see the SP and see the permissions on it but I could not run it. So to solve the issue I had to copy the text out of SQL Management Studio and paste it into Notepad, then remove the special character, then copy and paste it back into SQL Management Studio and run the alter script.

Very strange how the character got there!

Twiggz