title: In PowerShell how to troubleshoot exception in DataSet.Fill?
body: <p>I'm using a function I found on SO to retrieve data from SQL server and generate XML.</p>
  
  <pre><code>function Invoke-SQL {
      param(
          [string] $sqlCommand = $(throw "Please specify a query.")
        )
  
      $connectionString = "Data Source=$server;Initial Catalog=$database;user id=$uid;password=$pwd"
  
      $connection = new-object system.data.SqlClient.SQLConnection($connectionString)
      $command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
      $connection.Open()
  
      $adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
      $dataset = New-Object System.Data.DataSet
      $adapter.Fill($dataSet) | Out-Null
  
      $connection.Close()
      $tableOutput = $dataSet.Tables
  
      foreach($row in $tableOutput) {
          $xml  = $row | ConvertTo-Xml -NoTypeInformation -Depth 1
          $xml.InnerXML
      }
  }
  </code></pre>
  
  <p>It works most of the time but, occasionally, exactly the same SELECT (except for the range) from the same database and table would throw the following exception:</p>
  
  <pre><code>Exception calling "Fill" with "1" argument(s): "Incorrect syntax near '&gt;'."
  At DBTest.ps1:22 char:18
  +     $adapter.Fill &lt;&lt;&lt;&lt; ($dataSet) | Out-Null
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : DotNetMethodException
  </code></pre>
  
  <p>How to debug what rows and/or what data gets the Fill method to break?</p>