Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
I developed a desktop application in c# and it works nice; and i used stored procedures for database communications. I written 20 stored procedures to use in application. While installing application at client side they already have same database which i used in my app.Now i just have to add all procedures into their database, but adding 20 procedures is such a time consuming task . So i want to write a simple program which only add procedures to selected database. how to write this type of program?

Plz suggest some ideas.

What I have tried:

I tried some code but not getting exact idea
Posted
Updated 2-Feb-17 19:53pm

You need to generate the DROP and CREATE SQL Scripts for those Stored procedures. When you have the scripts, you could either run them directly on the customers or database or if you need the procedures to be created during installation, you can call the scripts from inside your application. Even if you are using Entity Framework you can just create a connection to the database and pass the SQL Script into an execute command as a SQL string.

To generate the SQL Scripts, open your SQL IDE, select your database, select the stored procedures folder and press F7. The list of procedures are displayed on the right. Select your 20 procs, right click and choose generate SQL Scripts.

good luck
 
Share this answer
 
Comments
Member 11543226 3-Feb-17 7:34am    
Thanks sir, it is very easy to create and use but can I call it from my application?
You simply make use of generate scripts feature in SSMS and create single file for all the SPs. Then, you just need to run it on the actual database.

You can find step by step process to do it here[^] on MSDN.
 
Share this answer
 
Comments
Member 11543226 3-Feb-17 7:34am    
Thanks.
Open an SqlConnection, create an SqlCommand object.
Set the command text to the CREATE PROC string: CREATE PROCEDURE (Transact-SQL)[^]
SQL
CREATE PROC myProcName   
AS   
BEGIN
   SELECT custName FROM customers;
END
 
Share this answer
 
Just prepare a script and execute that in the target machine. That's all!
There are even tools/components to do that but, I would recommend to make it simple by just following steps to create the script for all of your stored procedures.
--Go to Object Explorer
--Right click on the required database name
--Go to Tasks -> Generate Scripts
--Click next to switch to tab "Choose Objects"
--Select radio button "Select specific database objects"
--Choose the all stored procedure checkbox or only the required stored procedures
--Click Next
--Go to Advanced and choose "Script DROP and CREATE" from dropdwon beside "Script DROP and CREATE" field in the list
--Choose the path of the file to be stored
--Click Next and then Finish.

Now, just execute this script file in the target machine.
That's all !

If you really have such requirement to do this via C#, please revert me with your requirement and I'll try to help you out further.

Hope, it helps :)
 
Share this answer
 

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