Page 1 of 1

Validate an SQLCMD script has run successfully

Posted: Fri Aug 13, 2021 2:25 pm
by kwood
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.

Re: Validate an SQLCMD script has run successfully

Posted: Fri Aug 13, 2021 3:07 pm
by Stub
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.

Re: Validate an SQLCMD script has run successfully

Posted: Mon Aug 16, 2021 9:48 am
by kwood
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.