views:

28

answers:

3

How do I check that a stored procedure exists using ADO.Net? Is there a specific way to do this (apart from executing SELECT OBJECT_ID() and checking the result)?

+2  A: 

You can use the INFORMATION_SCHEMA views like so:

Select *
From INFORMATION_SCHEMA.ROUTINES
Where ROUTINE_NAME = '<your procedure name>'
Thomas
Is there a predefined method in ADO.Net to do this?
HeavyWave
@HeavyWire - No there is no built-in method to ADO.NET to determine the existence of a stored procedure. You must build a query that you call against SQL Server to determine if a procedure exists.
Thomas
A: 

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.

Aaronaught
A: 

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'
marc_s