When I am executing the below query:

EXECUTE dbo.IndexOptimize
            @Databases = 'USER_DATABASES',
            @FragmentationLow = NULL,
            @FragmentationMedium = NULL,
            @FragmentationHigh = NULL,
            @UpdateStatistics = 'ALL',
            @OnlyModifiedStatistics = 'Y'

I'm getting this error:

Msg 201, Level 16, State 4, Procedure dbo.CommandExecute, Line 0 [Batch Start Line 0]
Procedure or function 'CommandExecute' expects parameter '@DatabaseContext', which was not supplied.

Any help is appreciated.



  • Are you on the latest version of Ola's scripts? Nov 28, 2021 at 9:44
  • Yes, Dec 2020 version
    – Hany Helmy
    Nov 28, 2021 at 13:07

1 Answer 1


You most likely have a version mismatch between the IndexOptimize and CommandExecute procedures.

This is apparent from the error message you posted along with the version control done in a recent version of Ola's IndexOptimize procedure (reading the source code).

I would delete the 4 stored procedures and let his installation script create them anew. Be careful with what database you specify in the script. If you want his script to also re-create the jobs, then specify that in the installation script and delete the current jobs first.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.