Validate an SQLCMD script has run successfully

Best practices, code snippets for common functionality, examples, and guidelines.
kwood
Posts: 3
Joined: Fri Jun 25, 2021 2:27 pm

Validate an SQLCMD script has run successfully

Post by kwood » Fri Aug 13, 2021 2:25 pm

I am trying to work out how to achieve my test run to validate or ensure my script run through an SQLCMD has run successfully. I have been able to get it to also provide a text file output, but I really want to ensure the process gives the time for the command to run and then validate a successful finish.
I have the test opening up the CMD prompt windows on my desktop and then running the following code:

Code: Select all

sqlcmd -S serverIP -d DB name -U Username -P password -i C:\path\script.sql
This then runs the script, but I am not sure how to then allow this to run and then validate it was successful.

I have then also added this code below, which writes the ouptut to a text file:

Code: Select all

-0 C:\path\ouput.txt
But again, I do not know how to give this time to finish and validate it was successful.

Any help would be appreciated. Thank you.

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Validate an SQLCMD script has run successfully

Post by Stub » Fri Aug 13, 2021 3:07 pm

Years ago I integrated SQLCMD into some unit tests, by spawning a process that executes my SQLCMD command line, monitors the process to detect it exiting, then examines the exit code and any output sent to the error stream, IIRC. I daresay much the same can be achieved via a C# Code Module here too. Not something I've attemped however.

kwood
Posts: 3
Joined: Fri Jun 25, 2021 2:27 pm

Re: Validate an SQLCMD script has run successfully

Post by kwood » Mon Aug 16, 2021 9:48 am

Thank you for your comment.
Would you be able to point in the right direction for getting this type of code, please? Unfortunately, I am only able to do the UI front end, as I am not C# savvy.