I have one batch file with contents like:
@Echo Off
goto skipcomments
rem
:skipcomments
call setup-CIpatch-db.bat
if not "%UserName%"=="" goto ok
echo You must edit setup-CIpatch-db.bat to set variables.
echo This script no longer takes command line arguments.
goto end
:ok
if exist *.out del *.out
echo CoreIssue FleetOne Maintenance Release
echo working... DO NOT CLOSE
REM ************************************************
REM Script in which Print Statement has been removed
REM ************************************************
REM ************************************************
REM Create Scripts for Tables
REM ************************************************
REM ************************************************
REM Alter Scripts for Tables
REM ************************************************
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i AlterTablecardBacktable07312012.sql -o AlterTablecardBacktable07312012.out
REM ************************************************
REM Data Updates
REM ************************************************
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i AlterDrpandCrePrimKeyCardback.sql -o AlterDrpandCrePrimKeyCardback.out
REM ************************************************
REM Performance Updates
REM ************************************************
REM ************************************************
REM Security Update Scripts
REM ************************************************
REM ************************************************
REM Reports scripts
REM ************************************************
REM ************************************************
REM New or Altered Stored Procedures
REM ************************************************
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i sp_RejectAccounts_qsel.sql -o sp_RejectAccounts_qsel.out
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i sp_RejectAccounts_sel.sql -o sp_RejectAccounts_sel.out
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i sp_GetCompanyRecordCardRequest_01Aug2012.sql -o sp_GetCompanyRecordCardRequest_01Aug2012.out
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i SPGetCreditTransactions.sql -o SPGetCreditTransactions.out
REM ************************************************
REM Grant.sql for new or altered SP
REM ************************************************
REM ************************************************
REM Platform TranID Change Scripts
REM ************************************************
REM ************************************************
REM Version number update
REM ************************************************
osql -S %ServerName% -d %DBName% -U %sql_login% -P %sql_passwd% -n -i version.sql -o version.out
echo All Scripts have been started
:end
pause
The script executes SQL files in the same folder and generates files with the extension of '.out'. These just contain the result; the same as when we execute any query in SSMS messages window, like 1 row affected etc. After the batch file has finished executing all scripts (via ADO.net/C#), we have to check the out files for keywords like "error" etc.
Now I have been given task to automate this and here is what I am doing:
Fetch the .SQL file name in tha batch file and execute them using SqlConnection, SqlCommand etc. The problem is that when the query has any error in it, an exception is thrown. What I need is that the query should execute whatsoever and I should be able to get the results. (like 1 row affected etc). Like in SSMS, when we execute any bad query, it executes and show the error in the Messages Pane.
Can anyone guide me ?