Bill:
Bill said:
My SQL Server 2000 database has a number of user defined stored
procedures. I need a C# program (or if necessary, a database script)
to do the following:
1. Get a list of the stored procedures.
2. For each stored procedure, retrieve the SQL of this procedure to
text format and store it in a text file.
Does ADO.NET have any built-in method to do that? Thank you!
Bill
Ultimately you have two way, SQLDMO library and T-SQL. You can use them
both too, although I doubt you'd want to ...
If you query the Sysobjects tables, Stored Procs will have an XType of 'P'.
You'd query the Sysobjects table of the Database that's holding the procs
you are interested in .
Similarly, there's a system stored procedure. sp_Stored_Procedures which
will return the name and owner among other things. You can further filter
this by specifing the name (or use wildcards to guess) the owner or the
qualifier. In your case, it doesn't appear that you'd need any of these
filters.
Now, to get the text of the stored proc, you can do a few things. Through
T-SQL you can get a list of your procs, then loop through them and pass each
one's name to sp_helptext 'storedprocname'
You can do the same using the SQLDMO library and use Object.Text to retieve
the stored procs text. T-SQL Is pretty straightforward, but to access this
programatically SQLDMO may be a bit easier overall, it really depends on
your experience with SQL Server and the Library