{"id":74,"date":"2011-12-07T13:55:49","date_gmt":"2011-12-07T13:55:49","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2011\/12\/07\/msg-2812-level-16-state-62-line-1-could-not-find-stored-procedure\/"},"modified":"2011-12-07T13:55:49","modified_gmt":"2011-12-07T13:55:49","slug":"msg-2812-level-16-state-62-line-1-could-not-find-stored-procedure","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2011\/12\/07\/msg-2812-level-16-state-62-line-1-could-not-find-stored-procedure\/","title":{"rendered":"Msg 2812, Level 16, State 62, Line 1 Could not find stored procedure ”"},"content":{"rendered":"

This error message occurs when SQL server interprets the text you have given as a stored procedure and cannot find a procedure with that name.<\/p>\n

Possible reasons:<\/strong> <\/p>\n

Summary: <\/strong>
\nSyntax error in sql code, Mistyped SQL Code
\nStored procedure does not exist
\nStored procedure got deleted
\nMissing schema name of the procedure in the query
\nUsing exec with dynamic sql
\nUsing Unicode with osql
\nUsing extended stored procedures like xp_cmdshell on azure environment.<\/p>\n

In Detail:<\/strong>
\n– Mistyped SQL Code<\/strong>
\nExample:
\n[sql]
\nabcd
\n[\/sql]<\/p>\n

When you try to execute the above code you get the error
\nMsg 2812, Level 16, State 62, Line 1
\nCould not find stored procedure ‘abcd’.<\/font><\/p>\n

– SQL Server interprets the single word that is sent as a query as the name of stored procedure with no parameters. <\/strong><\/p>\n

Example:
\nCreate a stored procedure named abcd
\n[sql]
\nCREATE PROCEDURE abcd
\nAS
\nSELECT * FROM SYS.tables
\n[\/sql]<\/p>\n

Now try to execute the below query:
\n[sql]abcd[\/sql]<\/p>\n

The result would be the output of executing the procedure abcd.<\/p>\n

So in order to avoid the above error, when querying sql server using a single word then make sure that the procedure with that name exists.<\/p>\n

– You might expect the stored procedure with the name to exist but it isn\u2019t.<\/strong><\/p>\n

To check if the procedure exists you can use the below query:<\/p>\n

[sql]
\nSELECT * FROM SYS.PROCEDURES WHERE NAME LIKE ‘%PROCEDURENAME%’
\n[\/sql]
\nreplace PROCEDURENAME with the name of the procedure.<\/p>\n

– There could be a missing schema name of the procedure in the query<\/strong><\/p>\n

procedures with schema names would be like dbo<\/strong>.sp_abcd , products<\/strong>.sp_createproduct etc.<\/p>\n

To find the schema name of the stored procedure you can use the following query:<\/p>\n

[sql]select SCHEMA_NAME(schema_id),* from sys.procedures[\/sql]<\/p>\n

You can also alternatively use the below query:
\n[sql]
\nsp_help ‘PROCEDURENAME’
\n[\/sql]<\/p>\n

– This error could also be due to using exec with dynamic sql.<\/strong><\/p>\n

Try opening and closing the braces after exec to avoid such error, also you can use sp_executesql.<\/p>\n

[sql]<\/p>\n

exec (@dynamicsql)
\n–or
\nexec sp_executesql @dynamicsql<\/p>\n

[\/sql]<\/p>\n

– when using unicode with osql<\/strong><\/p>\n

osql ignores Unicode files, you need to use -u switch with the osql command.<\/p>\n

– Using SQL Azure and extended stored procedures<\/strong>
\nyou could be using azure environment and SQL Azure does not have the extended stored procedures like xp_cmdshell.<\/p>\n

<\/p>\n

Good coding standard would be to add exec statement beofore the name of the stored procedure.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"

This error message occurs when SQL server interprets the text you have given as a stored procedure and cannot find a procedure with that name. Possible reasons: Summary: Syntax error in sql code, Mistyped SQL Code Stored procedure does not exist Stored procedure got deleted Missing schema name of the procedure in the query Using…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[211,212,213,214],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/74"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}