开发者

Check if stored proc exists in ADO.Net?

开发者 https://www.devze.com 2022-12-28 04:50 出处:网络
How do I check that a stored procedure exists using ADO.Net? Is there a specific way to do this (apart from e开发者_JAVA百科xecuting SELECT OBJECT_ID() and checking the result)?You can use the INFORMA

How do I check that a stored procedure exists using ADO.Net? Is there a specific way to do this (apart from e开发者_JAVA百科xecuting SELECT OBJECT_ID() and checking the result)?


You can use the INFORMATION_SCHEMA views like so:

Select *
From INFORMATION_SCHEMA.ROUTINES
Where ROUTINE_NAME = '<your procedure name>'


If you're asking whether or not there's a way to check without using any SQL at all, then the answer is no.

You could use SQL Management Objects if you really want a code-only solution, but that's a pretty heavy dependency to add simply to check for the existence of a stored procedure - and it's just going to issue SQL behind the scenes anyway.

It's best if you simply use a SqlCommand.


Or if you don't care about adhering to SQL standard constructs (INFORMATION_SCHEMA), you can use the built-in SQL Server system catalog view (2005 and up) to check:

SELECT object_id, name
FROM sys.procedures
WHERE name = 'your-procedure-name-here'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号