.Net backup of SQL stored procedures

I would like to build a .net procedure that exports all stored procedures in SQL Server Database on a click event

How would I pull that into .net on a "for each" basis and create the file?
Larry Bristersr. DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
I am assuming that you already know the .NET part very well, connecting to SQL Server, getting a SqlDataReader all the related stuff.

If yes, first fire the following query to get name of all stored procedures.

select object_id, name from sys.procedures order by 2

Open in new window


Loop through above record set and in the loop fire the following query:

select text from sys.syscomments where id = ? -- put object_id from above query here

Open in new window


Take that first column in a string variable, preferably with ExecuteScalar and write it to the text file. Name the file as the name of the stored procedure. Simple.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Larry Bristersr. DeveloperAuthor Commented:
Perfect... that's it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.