Since we don’t know how Management Studio processes the data, I recommend examining the string before and after DefineEncoding in the debugger. You might see something there that will help you track down the error.
If the database is storing fields using UTF8 and you application is then no conversions should be required. Just ensure that strings have an encoding, typically those returned from a database do not.
I’d like to suggest a more understandable version of your code. This will make it easier to read it in the forum and help you.
// Helper function for masking single quotes in text fields
Function SanitizeSQLText(input As String) As String
Return input.ReplaceAll("'", "‘’").DefineEncoding(Encodings.UTF8)
End Function
// Helper function for creating a timestamp in the format YYYYMMDDHHMMSS
Function GetTimestamp(dateText As String, timeText As String) As String
Return dateText.MidB(7,4) + dateText.MidB(4,2) + dateText.MidB(1,2) + _
timeText.MidB(1,2) + timeText.MidB(4,2) + timeText.MidB(7,2)
End Function
Don’t build sql like that. It is very dangerous. Read about sql injection.
The user interface works in UTF8, check that before you do anything else. If it is something else, then a convert will be required.
When opening the database tell it you are using UTF8, so the engine doesn’t convert it to something else. For MySQL use (Set names “UTF8”) for example.
Ensure that your database is built to use UTF8. Check storage types and sorting methods.
When reading data back from the database ensure everything has a defined encoding and it is UTF8. If it is nil define it. If the data is still wrong check the database and driver is working in UTF8.
There should be other threads with solutions in the forum already. This comes up a lot.