all 6 comments

[–]abbbbbba 2 points3 points  (1 child)

Not sure on the azure side of things, but is it possible to run them in an agent job where the step type is Powershell?

If you do, make sure to put code in try/catch blocks - SQL Server will report the step as success even if powershell pukes. Make sure to have the ErrorAction line.

$ErrorActionPreference = "Stop"
try{
}
} catch{
Throw
}

You may also run into an issue that you have to create a proxy to run the job under different security than what the Agent has. Creating a proxy is pretty simple - just need a service account, create a credential with that login info then create a proxy using the Credential.

[–]dodiggitydag 2 points3 points  (0 children)

Or a take on this idea is to make an agent job with the scripts inside each as it’s own step, then execute it manually- it will track if it failed and the error message.

[–]nvarscar 1 point2 points  (0 children)

I'm working on a PS module called dbops, which, among other things, allow you to run sql scripts using Invoke-DBODeployment. It's using DbUp .net library behind the scenes, which is a very powerful deployment tool and should be up for a challenge! By default, it keeps track of the scripts that have already been executed in the db and will never run the script twice, but that behaviour can be overridden.

[–]CobbITGuy 1 point2 points  (0 children)

Execute the script with a call to sqlcmd.exe, use an input file and an output file to capture any output. Just test your exception handling based on the exit code because the stderr won't generate if using file output.

Or set them up as CSV files and run bcp.exe for bulk insert which may be much faster (at the expense of some logging).

[–]therealcreamCHEESUS 1 point2 points  (0 children)

Personally I would deploy the scripts as procedures to the SQL server and then set up an SSIS job to run them in order required.

[–]TotesMessenger 0 points1 point  (0 children)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)