title: Inserting special characters in database with IBM.Data.DB2.ISeries provider
body: <p>I've been having an issue with an app written in VB.Net that relies on an iSeries database. Users can save notes, which (very) often are copy/pasted from their mailbox. </p>
  
  <p>But many mails contain invalid characters that trigger iDb2ConversionException when the data is saved to the database.</p>
  
  <p>For the time being, I scrub the data, replacing invalid characters with matching html entities, but I really dislike that approach :</p>
  
  <ul>
  <li>I have to maintain a conversion list, and even though I managed to cover most invalid characters, new ones always come up.</li>
  <li>If I run the same command using STRSQL in Client Access, I can actually insert those invalid characters.</li>
  <li>We have many fixed-length fields, and replacing chars with HTML entities makes it a lot harder to enforce maximum string lengths at the UI level</li>
  </ul>
  
  <p>The same command works with ADO.NET if I don't use parameters (but then I have to scrub user input again, so all in all... it just moves the problem elsewhere)</p>
  
  <pre><code>Dim command = connection.CreateCommand()
  command.CommandText = "UPDATE table SET field = '€€€€€]]]]]]]]]]]°°°°°°§§§§§' where ...."
  command.ExecuteNonQuery() ' Executes successfully '
  
  Dim command = connection.CreateCommand()
  command.CommandText = "UPDATE table SET field = @value where ...."
  command.DeriveParameters()
  command.Parameters("@value").Value = "'€€€€€]]]]]]]]]]]°°°°°°§§§§§'"
  command.ExecuteNonQuery() ' Throws iDb2ConversionException '
  </code></pre>
  
  <p>My connection string is as follows :</p>
  
  <pre><code>Datasource=server;DataBase=DBNAME;DefaultCollection=DBCOLLECTION;HexParserOption=Binary;LibraryList=LIBRARIES;Naming=SQL;DataCompression=True;AllowUnsupportedChar=true;
  </code></pre>
  
  <p>Is there any option available to successfully write those characters to the DB without getting that exception ?</p>