Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to pass parameters into sql jobs?

How to pass parameters into sql jobs?

Scheduled Pinned Locked Moved ASP.NET
databasetutorialquestioncareer
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashish bhakhar
    wrote on last edited by
    #1

    How to pass the parameters of @dbName, @LogicalName, @ToServer to job dynamically using stored procedure?

    C 1 Reply Last reply
    0
    • A ashish bhakhar

      How to pass the parameters of @dbName, @LogicalName, @ToServer to job dynamically using stored procedure?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      This belongs in the SQL forum, where I'd advise you to look into how google works. Parameters are specified by adding them to the parameters collection, heaps of info on the web, or in your books.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      A 1 Reply Last reply
      0
      • C Christian Graus

        This belongs in the SQL forum, where I'd advise you to look into how google works. Parameters are specified by adding them to the parameters collection, heaps of info on the web, or in your books.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        A Offline
        A Offline
        ashish bhakhar
        wrote on last edited by
        #3

        hello Christian Graus i cant find reply of this question in sql forum, that's why for fast reply i put it here.

        C 1 Reply Last reply
        0
        • A ashish bhakhar

          hello Christian Graus i cant find reply of this question in sql forum, that's why for fast reply i put it here.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          And what did you find with google ? What code are you using to call your proc ?

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          A 1 Reply Last reply
          0
          • C Christian Graus

            And what did you find with google ? What code are you using to call your proc ?

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            A Offline
            A Offline
            ashish bhakhar
            wrote on last edited by
            #5

            nothing find from google. that's why i put my question here. i have more expectations from codeproject than google. This is my sql job: USE [master] GO declare @file as varchar(500) declare @dbName as varchar(50) declare @LogicalName as varchar(50) declare @ToServer as varchar(50) exec('ALTER DATABASE ['+@dbName+'] SET SINGLE_USER WITH ROLLBACK IMMEDIATE') exec('RESTORE DATABASE ['+@dbName+'] FROM DISK = N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\'+@file+''' WITH FILE = 1, MOVE N'''+@LogicalName+''' TO N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\'+@dbName+'.mdf'', MOVE N'''+@LogicalName+'_log'' TO N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\'+@dbName+'_log.ldf'', NOUNLOAD, REPLACE, STATS = 10') GO I want to pass above four parameters like @file,@dbName,@LogicalName,@ToServer from my stored procedure to above job. so, what i have to do for this? this is my stored procedure: ALTER PROCEDURE runjob AS Declare @backupfile varchar(500),@databasename varchar(50), @logicaldatabasename varchar(50), @toservername varchar(50) set @backupfile = 'test1.bak'; set @databasename = 'test1'; set @logicaldatabasename = 'test1'; set @toservername = 'Live'; BEGIN --exec sp_who2 EXEC msdb.dbo.sp_add_job @job_name = 'k', @file = @backupfile, @dbName = @databasename, @LogicalName = @logicaldatabasename, @ToServer = @toservername EXEC msdb.dbo.sp_start_job k END so, what i have to do for this? and i m receiving an error @file is not a parameter for procedure sp_add_job.

            S C 2 Replies Last reply
            0
            • A ashish bhakhar

              nothing find from google. that's why i put my question here. i have more expectations from codeproject than google. This is my sql job: USE [master] GO declare @file as varchar(500) declare @dbName as varchar(50) declare @LogicalName as varchar(50) declare @ToServer as varchar(50) exec('ALTER DATABASE ['+@dbName+'] SET SINGLE_USER WITH ROLLBACK IMMEDIATE') exec('RESTORE DATABASE ['+@dbName+'] FROM DISK = N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\'+@file+''' WITH FILE = 1, MOVE N'''+@LogicalName+''' TO N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\'+@dbName+'.mdf'', MOVE N'''+@LogicalName+'_log'' TO N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\'+@dbName+'_log.ldf'', NOUNLOAD, REPLACE, STATS = 10') GO I want to pass above four parameters like @file,@dbName,@LogicalName,@ToServer from my stored procedure to above job. so, what i have to do for this? this is my stored procedure: ALTER PROCEDURE runjob AS Declare @backupfile varchar(500),@databasename varchar(50), @logicaldatabasename varchar(50), @toservername varchar(50) set @backupfile = 'test1.bak'; set @databasename = 'test1'; set @logicaldatabasename = 'test1'; set @toservername = 'Live'; BEGIN --exec sp_who2 EXEC msdb.dbo.sp_add_job @job_name = 'k', @file = @backupfile, @dbName = @databasename, @LogicalName = @logicaldatabasename, @ToServer = @toservername EXEC msdb.dbo.sp_start_job k END so, what i have to do for this? and i m receiving an error @file is not a parameter for procedure sp_add_job.

              S Offline
              S Offline
              saini arun
              wrote on last edited by
              #6

              Specify all parameters like this... ALTER PROCEDURE runjob @file1 varchar(50). @directoryName varchar(50) AS

              “The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep.”

              1 Reply Last reply
              0
              • A ashish bhakhar

                nothing find from google. that's why i put my question here. i have more expectations from codeproject than google. This is my sql job: USE [master] GO declare @file as varchar(500) declare @dbName as varchar(50) declare @LogicalName as varchar(50) declare @ToServer as varchar(50) exec('ALTER DATABASE ['+@dbName+'] SET SINGLE_USER WITH ROLLBACK IMMEDIATE') exec('RESTORE DATABASE ['+@dbName+'] FROM DISK = N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\'+@file+''' WITH FILE = 1, MOVE N'''+@LogicalName+''' TO N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\'+@dbName+'.mdf'', MOVE N'''+@LogicalName+'_log'' TO N''F:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\'+@dbName+'_log.ldf'', NOUNLOAD, REPLACE, STATS = 10') GO I want to pass above four parameters like @file,@dbName,@LogicalName,@ToServer from my stored procedure to above job. so, what i have to do for this? this is my stored procedure: ALTER PROCEDURE runjob AS Declare @backupfile varchar(500),@databasename varchar(50), @logicaldatabasename varchar(50), @toservername varchar(50) set @backupfile = 'test1.bak'; set @databasename = 'test1'; set @logicaldatabasename = 'test1'; set @toservername = 'Live'; BEGIN --exec sp_who2 EXEC msdb.dbo.sp_add_job @job_name = 'k', @file = @backupfile, @dbName = @databasename, @LogicalName = @logicaldatabasename, @ToServer = @toservername EXEC msdb.dbo.sp_start_job k END so, what i have to do for this? and i m receiving an error @file is not a parameter for procedure sp_add_job.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Oh.... see, not only was this entirely a SQL question ( did you post it there ? ), but you were not asking what I thought you were asking. I kept asking you how you called the proc, b/c I thought you wanted to know how to pass the parameter into the proc. Really, you wanted to know how to write a stored proc in the first place. This is where posting code really helps, if you'd done that in the first place, I'd have made sense of your question and answered it ( the way you pass params into a proc depends on how you're calling it in .NET code, that's why I kept asking that and not giving a full answer ).

                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups