You must Sign In to post a response.
  • Category: .NET

    How to write program to add stored procedures into SQL server database?

    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.
  • #768839
    Hi

    You can try backup and restore using job concept thats best way for your tasks
    very simple and quickly you can achieve your task

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #768847
    Hi,

    adding procedure in to database is single time activity only for that why you need program?

    If you still need to add it using program then prepare either console or one time job like timer jobs that will help you.

    Refer below link to create / add stored procedure in to database.

    https://msdn.microsoft.com/en-us/library/5czye81z(v=vs.100).aspx

    Hope this helps you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #768983
    Hai Priya,
    I didn't understand the actual requirements for you. Writing 20 stored procedure is time consuming is not valid because anyhow you need to write the stored procedures based on the requirements. So the program cant write in its own. Also once you write the stored procedure you need to simply run it to get in to the database, that could be local database or remote database.
    What you can do is to write all the stored procedure in to single sql file and then execute them in a single shot so you need not to worry about executing them individually.
    By this way, you can make the thing faster.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768985
    Hi,

    As Pawan Mentioned, you are not gonna rewrite the Stored Procedure right. You gonna take the stored procedure from your local database and create a script file and then execute the script file in the database which is gonna update your application.

    For creating script file use the following format which is helpful and safe.

    IF NOT EXISTS(select definition from sys.sql_modules where object_id = object_id('sp_myprocedurename'))
    THEN
    CREATE PROC Proc_Name
    Begin

    your code

    END

    IF NOT Exists(select definition from sys.sql_modules where object_id = object_id('sp_myprocedurename2'))
    THEN
    CREATE PROC Proc_Name2
    Begin

    your code

    END

    .
    .
    .
    .


    Thanks,
    Mani


  • Sign In to post your comments