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.
But many mails contain invalid characters that trigger iDb2ConversionException when the data is saved to the database.
For the time being, I scrub the data, replacing invalid characters with matching html entities, but I really dislike that approach :
- I have to maintain a conversion list, and even though I managed to cover most invalid characters, new ones always come up.
- If I run the same command using STRSQL in Client Access, I can actually insert those invalid characters.
- 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
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)
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 '
My connection string is as follows :
Datasource=server;DataBase=DBNAME;DefaultCollection=DBCOLLECTION;HexParserOption=Binary;LibraryList=LIBRARIES;Naming=SQL;DataCompression=True;AllowUnsupportedChar=true;
Is there any option available to successfully write those characters to the DB without getting that exception ?