• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 44
  • Last Modified:

.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?
0
Larry Brister
Asked:
Larry Brister
1 Solution
 
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
 
Larry Bristersr. DeveloperAuthor Commented:
Perfect... that's it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now