Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
how do you get a full list of procedures from a specific database?

I have gotten the database name, and now all i need to do is use that db name to get a full list of procedures for that specific database.

please help...

the db name will be put into a string variable 'strDbName'.

This is what i have so far...
C#
string dbName = listBox1.SelectedItem.ToString();
            string conxString_2 = "Data Source=LUKE-PC; Integrated Security=True; Initial Catalog=" + dbName + "";

            using (SqlConnection sqlConx_2 = new SqlConnection(conxString_2))
            {
                sqlConx_2.Open();

                SqlCommand sqlcom = new SqlCommand();
                sqlcom.Connection = sqlConx_2;
                sqlcom.CommandType = CommandType.StoredProcedure;
                sqlcom.CommandText = "select * from sys.objects where type='p' and is_ms_shipped=0 and [name] not like 'sp[_]%diagram%'";

                SqlDataReader sqldr;
                sqldr = sqlcom.ExecuteReader();

                while (sqldr.Read())
                {
                    listBox1.Items.Add(sqldr.GetString(0));
                }
            }


It shows an error at (sqldr = sqlcom.ExecuteReader();) saying, Could not find stored procedure ''.

I just dont know what i'm doing wrong please help...
Posted
Updated 1-Jun-12 4:57am
v2

hi,


try this

SQL
Select * from sys.objects where type=’p’ and is_ms_shipped=0 and [name] not like ‘sp[_]%diagram%’


i have taken this from
listing-dropping-all-stored-procedures
 
Share this answer
 
v2
Comments
D3m0n1CMoNkEy 1-Jun-12 10:58am    
I have updated my question, i used the piece of code you gave and i still get an error, please have a look at the updated question to see if you can find out what im doing wrong. Thanks
D3m0n1CMoNkEy 1-Jun-12 12:01pm    
thanks with yours and Manfred R. Bihy advice, it works, thank you
The simplest way to use sp_stored_procedures is to call it with no arguments:
SQL
exec sp_stored_procedures

Ref: List stored procedures[^]

Or else

Run following simple script on SQL Server 2005 to retrieve all stored procedure in database.
SQL
SELECT *
FROM sys.procedures;


This will ONLY work with SQL Server 2005.

Also have look on:
List stored procedures in MySQL[^]
List All Stored Procedure in Database[^]
 
Share this answer
 
Comments
deepureddy18 1-Jun-12 8:10am    
exec sp_stored_procedures
Manas Bhardwaj 1-Jun-12 11:12am    
on the spot. +5
Prasad_Kulkarni 2-Jun-12 3:28am    
Thank you Manas!
Instead of using CommandType.StoredProcedure[^] you need to use CommandType.Text[^]. The reason is that you are not calling a stored procedure, but rather calling an SQL statement that queries the DMBS's system tables.

If you were to use Prasad Kulkarni's[^] advice of calling a system stored procedure to enumerate all stored procedures, then CommandType.StoredProcudure would be nescessary.

Regards,

Manfred
 
Share this answer
 
v2
Comments
Manas Bhardwaj 1-Jun-12 11:12am    
+5
Manfred Rudolf Bihy 1-Jun-12 11:32am    
Thanks! :)
D3m0n1CMoNkEy 1-Jun-12 12:00pm    
thanks that did the trick ;)
Manfred Rudolf Bihy 1-Jun-12 12:04pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900