batch file to call a procedure from sql

  • hi all,

    i had to write a batch file which runs at the start up of windows  and it must call a procedure from sql which is given by us. can anyone help me to write the batch file

  • Hi sunil,

            If you think of executing the Stored Procedure(SP) during the Windows startup then it is wrong thing to do. B'coz the SQL Server has to start for running your SP.

           But don't worry there is a solution for running the Stored Procedure when you start the Microsoft® SQL Server™.

          Use "sp_procoption" for setting up the SP for Autoexecution. This will make the SP to execute every time the SQL Server Starts up.

          I think you will find more help for "sp_procoption" in MSSQL Books Online.

          Still you are not clear about this reply me.

    Thanks and Regards,

    Ankush

    ankush.choudera@slk-soft.com

  • Sunil,

      I would agree with Ankush if your SQL Server is on the same machine that you want the batch file to run.  SQL Services will likely not be started when your script runs.

      Using a Startup Procedure can be a solution, but note that there can be only 1 Startup Procedure for a server.

      If your SQL Server is remote, and you don't need to return data, you could just add a line like this to your batch file:

    osql -S myServer -E -Q "Select @@version"

      It gets a little more difficult if you need the procedure to return data for you to act on.  If that is the case, I'd go with something like VBScript rather than a batch file.

    Best of luck,

    Steve


    Regards,
    Steve

    Meddle not in the affairs of dragons, for you are crunchy and taste good with ketchup.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply