Skip to content

Commit

Permalink
Merge pull request RamblingCookieMonster#17 from ShiyangQiu/master
Browse files Browse the repository at this point in the history
* Fixed the verbose option and SQL error handling conflict
* !Deploy
  • Loading branch information
RamblingCookieMonster authored Sep 13, 2016
2 parents f955321 + 714f233 commit a66ba0b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Invoke-Sqlcmd2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
- Added ErrorAction SilentlyContinue handling to Fill method
v1.6.0 - Added SQLConnection parameter and handling. Is there a more efficient way to handle the parameter sets?
- Fixed SQLConnection handling so that it is not closed (we now only close connections we create)
v1.6.1 - Shiyang Qiu - Fixed the verbose option and SQL error handling conflict
.LINK
https://github.com/RamblingCookieMonster/PowerShell
Expand Down Expand Up @@ -448,7 +449,7 @@
#Following EventHandler is used for PRINT and RAISERROR T-SQL statements. Executed when -Verbose parameter specified by caller
if ($PSBoundParameters.Verbose)
{
$conn.FireInfoMessageEventOnUserErrors=$true
$conn.FireInfoMessageEventOnUserErrors=$false # Shiyang, $true will change the SQL exception to information
$handler = [System.Data.SqlClient.SqlInfoMessageEventHandler] { Write-Verbose "$($_)" }
$conn.add_InfoMessage($handler)
}
Expand Down Expand Up @@ -478,14 +479,16 @@
$conn.Close()
}
}
Catch
Catch [System.Data.SqlClient.SqlException]
{
$Err = $_
if(-not $PSBoundParameters.ContainsKey('SQLConnection'))
{
$conn.Close()
}

if ($PSBoundParameters.Verbose) {Write-Verbose "SQL Error: $Err"} #Shiyang, add the verbose output of exception

switch ($ErrorActionPreference.tostring())
{
{'SilentlyContinue','Ignore' -contains $_} {}
Expand Down

0 comments on commit a66ba0b

Please sign in to comment.