When running the auto discovery agent there is an option to grant the needed database privileges manually. Using the provided script as it is it throws an error: Wrong syntax.
This line is not correct:
Select @LoginName = ?;
You need to be signed in and under a current maintenance contract to view premium knowledge articles.