Hi,
I've experienced an issue using Invoke-SQLCmd2 against the same instance of a SQLConnection object.
The command is :
Invoke-SQLCmd2 -SQLConnection $sqlconn -Query "PRINT 'Hello';" -Verbose
The first time, I get the expected output, which is VERBOSE: Hello
But, each time I run the command, I get extra lines that come.
The problem is there (there is a little modification from @RamblingCookieMonster's repository, but that do not change the things here)
Following EventHandler is used for PRINT and RAISERROR T-SQL statements. Executed when -Verbose parameter specified by caller
if ($PSBoundParameters.Verbose)
{
$conn.FireInfoMessageEventOnUserErrors=$false # Shiyang, $true will change the SQL exception to information
$handler = [System.Data.SqlClient.SqlInfoMessageEventHandler] { Write-Verbose "$($_)" }
$conn.add_InfoMessage($handler)
}
Is there a way to detect a SQL Connection has already a "verbose handler" ?