DECLARE @hr int, @source varchar(255), @description varchar(255) DECLARE @RetCode int, @oServer int, @oAgent int, @Status int, @Err int EXECUTE @RetCode = sp_OACreate 'SQLDMO.SQLServer', @oServer OUTPUT SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler PRINT 'Use Windows login' EXECUTE @RetCode = sp_OASetProperty @oServer, 'LoginSecure', 1 SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler IF @RetCode <> 0 BEGIN EXEC @hr = sp_OAGetErrorInfo @oServer, @source OUT, @description OUT GOTO DisplayError END PRINT 'Connect' EXECUTE @RetCode = sp_OAMethod @oServer, 'Connect' SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler IF @RetCode <> 0 BEGIN EXEC @hr = sp_OAGetErrorInfo @oServer, @source OUT, @description OUT GOTO DisplayError END PRINT 'Get Agent object' EXECUTE @RetCode = sp_OAGetProperty @oServer, 'JobServer', @oAgent OUTPUT SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler IF @RetCode <> 0 BEGIN EXEC @hr = sp_OAGetErrorInfo @oServer, @source OUT, @description OUT GOTO DisplayError END PRINT 'Get Agent Status and Stop/Start it based on the current status' EXECUTE @RetCode = sp_OAGetProperty @oAgent, 'Status', @Status OUTPUT SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler IF @RetCode <> 0 BEGIN EXEC @hr = sp_OAGetErrorInfo @oAgent, @source OUT, @description OUT GOTO DisplayError END IF @Status = 1 BEGIN PRINT 'Agent is running' PRINT 'Stop it' EXECUTE @RetCode = sp_OAMethod @oAgent, 'Stop' SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler IF @RetCode <> 0 BEGIN EXEC @hr = sp_OAGetErrorInfo @oServer, @source OUT, @description OUT GOTO DisplayError END END ELSE IF @Status = 3 BEGIN PRINT 'Agent is stopped' PRINT 'Start it' EXECUTE @RetCode = sp_OAMethod @oAgent, 'Start' SET @Err = @@ERROR IF @Err > 0 GOTO ErrorHandler IF @RetCode <> 0 BEGIN EXEC @hr = sp_OAGetErrorInfo @oServer, @source OUT, @description OUT GOTO DisplayError END END ELSE PRINT 'Agent Status: ' + CAST(@Status AS varchar(10)) GOTO Cleanup ErrorHandler: PRINT 'ERROR: ' + CAST(@err AS varchar(10)) GOTO Cleanup DisplayError: PRINT 'OLE Automation Error Information' IF @hr = 0 BEGIN PRINT ' Source: ' + @source PRINT ' Description: ' + @description END GOTO Cleanup Cleanup: IF @oServer IS NOT NULL EXECUTE @RetCode = sp_OADestroy @oServer IF @oAgent IS NOT NULL EXECUTE @RetCode = sp_OADestroy @oAgent RETURN>is there a way to start the sql server agent using transact sql ??