次のような内容のバッチファイルが 1 つあります。
@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
スクリプトは、同じフォルダー内の SQL ファイルを実行し、拡張子が「.out」のファイルを生成します。これらには結果が含まれているだけです。影響を受ける 1 行など、SSMS メッセージ ウィンドウで任意のクエリを実行する場合と同じです。バッチ ファイルがすべてのスクリプトの実行を終了した後 (ADO.net/C# 経由)、「エラー」などのキーワードのファイルをチェックアウトする必要があります。等
今、私はこれを自動化するタスクを与えられており、ここで私がやっていることは次
のとおりです。バッチファイルで.SQLファイル名を取得し、SqlConnection、SqlCommandなどを使用して実行します。問題は、クエリにエラーがある場合、例外がスローされます。私が必要とするのは、クエリが実行され、結果を取得できることです。(影響を受ける1行など)。SSMS と同様に、不適切なクエリを実行すると、実行されてメッセージ ペインにエラーが表示されます。
誰でも私を案内できますか?