Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Scripting Jobs using DMO and vbs, generates bad .sql script

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-02 : 08:12:10
Andy writes "SQL7, NT4
Any suggestions as to why when scripting JOBS using SQLDMO to generate a .sql script does the script become bad.

example of generated script:
begin transaction
DECLARE @JobID BINARY(16)
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
if (select count(*) from msdb.dbo.syscategories where name = N'Database Maintenance') < 1
execute msdb.dbo.sp_add_category N'Database Maintenance'
select @JobID = job_id from msdb.dbo.sysjobs where (name = N'Integrity Checks Job for DB Maintenance Plan ''STD Maintenance''')
if (@JobID is not NULL)
begin
if (exists (select * from msdb.dbo.sysjobservers where (job_id = @JobID) AND (server_id <> 0)))
begin
RAISERROR (N'Unable to import job since there is already a multi-server job with this name.', 16, 1)
goto QuitWithRollback
end else
execute msdb.dbo.sp_delete_job @job_name = N'Integrity Checks Job for DB Maintenance Plan ''STD Maintenance'''
select @JobID = NULL
end
BEGIN
execute @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT @job_name = N'Integrity Checks Job for DB Maintenance Plan ''STD Maintenance''', @enabled = 1, @start_step_id = 1, @notify_level_eventlog = 2, @notify_level_email = 0, @notify_level_netsend = 0, @notify_level_page = 0, @delete_level = 0, @description = N'No description available.', @category_name = N'Database Maintenance', @owner_login_name = N'ME\thor', @notify_email_operator_name = N'(unknown)', @notify_netsend_operator_name = N'(unknown)', @notify_page_operator_name = N'(unknown)',
if (@@ERROR <> 0 OR @ReturnCode <> 0) goto QuitWithRollback
execute @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID , @step_id = 1, @cmdexec_success_code = 0, @on_success_action = 1, @on_success_step_id = 0, @on_fail_action = 2, @on_fail_step_id = 0, @retry_attempts = 0, @retry_interval = 0, @os_run_priority = 0, @flags = 4, @step_name = N'Step 1', @subsystem = N'TSQL', @command = N'EXECUTE master.dbo.xp_sqlmaint N''-PlanID 6ECD9D29-F99A-11D3-ADAA-00D0B73E8067 -Rpt "C:\MSSQL7\LOG\STD Maintenance2.txt" -DelTxtRpt 2WEEKS -CkDBRepair ''', @database_name = N'master'
if (@@ERROR <> 0 OR @ReturnCode <> 0) goto QuitWithRollback
execute @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
if (@@ERROR <> 0 OR @ReturnCode <> 0) goto QuitWithRollback
execute @ReturnCode = msdb.dbo.sp_add_jobschedule @job_id = @JobID, @name = N'Schedule 1', @enabled = 1, @freq_type = 8, @freq_interval = 1, @freq_subday_type = 1, @freq_subday_interval = 0, @freq_relative_interval = 0, @freq_recurrence_factor = 1, @active_start_date = 20000405, @active_end_date = 99991231, @active_start_time = 0, @active_end_time = 235959
if (@@ERROR <> 0 OR @ReturnCode <> 0) goto QuitWithRollback
execute @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
if (@@ERROR <> 0 OR @ReturnCode <> 0) goto QuitWithRollback
END
commit transaction
goto EndSave
QuitWithRollback:
if (@@TRANCOUNT > 0) rollback transaction
EndSave:

Example vbs script:
Dim oServer
Dim iServer
Dim JobCount
Dim CurrentJob
iServer = ucase(inputbox("Enter SQL Server name","Create Logins Script"))
Set oServer = wscript.CreateObject("SQLDMO.SQLServer")
if iserver = "" then
else
oServer.LoginSecure = 1
oServer.Connect (iserver)
CurrentJob = 1
JobCount = oServer.jobserver.jobs.Count
While CurrentJob <= JobCount
oServer.jobserver.Jobs(CurrentJob).Script 325, "a:\" & iServer & "JobScript.sql", 0
CurrentJob = CurrentJob + 1
Wend
end if
msgbox "Finished",0,"User Notification"
Set oServer = Nothing

The error will show up in query analyser on line 22/23 missing comma after OUTPUT and extra comma at end of line 22
Is this an error or am I missing somthing?
I know I can always script this from the enterprise manager and it works ok, but I need to keep things

vickie
Starting Member

1 Post

Posted - 2004-10-12 : 22:47:56
Do you have the answer to this? I have the same problem.
Go to Top of Page
   

- Advertisement -