forked from tSQLt-org/tSQLt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlcmdErrorHandling.ps1
More file actions
25 lines (19 loc) · 842 Bytes
/
Copy pathsqlcmdErrorHandling.ps1
File metadata and controls
25 lines (19 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Param(
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $ServerName,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $Login,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $SqlCmdPath
);
$sqlFileForTesting = @"
RAISERROR('an error',15,2);
GO
RAISERROR('no error 1',0,1)WITH NOWAIT;
GO
RAISERROR('no error 2',0,1)WITH NOWAIT;
GO
"@;
Set-Content "sqlFileForTesting.sql" $sqlFileForTesting;
#$CallSqlCmd = '&"'+$SqlCmdPath+'\sqlcmd.exe" -S "'+$ServerName+'" '+$Login+' -I -b -Q "RAISERROR (''an error!'',15,3)"';
$CallSqlCmd = '&"'+$SqlCmdPath+'\sqlcmd.exe" -S "'+$ServerName+'" '+$Login+' -I -b -i "sqlFileForTesting.sql"';
$CallSqlCmd;
$CallSqlCmd = $CallSqlCmd + ';if($LASTEXITCODE -ne 0){throw "error during execution";}'
Invoke-Expression $CallSqlCmd;