HELP! Message: The data could not be converted to text with this encoding.

  1. 2 weeks ago

    Richard A

    Feb 10 Pre-Release Testers, Xojo Pro Puerto Vallarta Mexico

    Have a record in our database that is causing this exception on a web app.

    Unhandled RuntimeException
    Message: The data could not be converted to text with this encoding.

    I have put this on every field = DefineEncoding(RecordSet.Field("FieldName"), Encodings.UTF8 )

    But it still throws exception.

    Is there a way I can get this data to load without throwing an exception.

    Is there some sql statement I can run this record through to clean it up.

  2. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...

    what sort of database is this ? mysql ? postgresql ? oracle ? mssql ?

    that message is simply telling you this data is NOT UTF-8
    however you put that data in you should use that encoding when you pull the data out

  3. Richard A

    Feb 10 Pre-Release Testers, Xojo Pro Puerto Vallarta Mexico

    MySql

    The data went in without the
    DefineEncoding(RecordSet.Field("FieldName"), Encodings.UTF8 )
    How can I get it out.

    The record was created by a Canadian user.
    In hindsight do I need to have every text field going into the DB wrapped with the DefineEncoding?

    Or is there another betterway way to do it.

  4. Michael H

    Feb 10 Pre-Release Testers, Xojo Pro Europe (Hamburg, Germany)

    You convert the encoding (if necessary, i.e. if it isn’t UTF8 to begin with) before putting text in the database and you define the encoding after you have retrieved text from the database. Of course you need to make sure that the encoding is the one you assert it to be.

  5. Richard A

    Feb 10 Pre-Release Testers, Xojo Pro Puerto Vallarta Mexico

    The data just went in the way the user entered it.

    I can't get it out.

  6. Louis D

    Feb 10 Pre-Release Testers, Xojo Pro QC, Canada

    The RDBMS should have a default encoding parameter. That should be the encoding of the string if none was specified.

  7. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...
    Edited 2 weeks ago

    do you happen to set the mysql "names" on connect
    https://dev.mysql.com/doc/refman/8.0/en/set-names.html
    basically a sql execute

    sqlexecute ("set names utf-8")

    this will tell the mysql server to return whatever data as ut8 not in whatever charset it might be configured to use

  8. Richard A

    Feb 10 Pre-Release Testers, Xojo Pro Puerto Vallarta Mexico

    I open the DB with:

    self.SQLExecute("Set NameS 'utf8'")
    
    
    self.DatabaseName = gsDatabaseName 
    self.Password = gsPassword 
    self.UserName =  gsUserName 
    self.Port = gnDBPort  
    self.Host = gsHost 
    
    
    if self.Connect = false then
      'self = nil
      MsgBox(self.ErrorMessage)
      return false
    end
    
  9. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...
    Edited 2 weeks ago

    you have the sql execute before the connect ???????
    that wont work right

    edit - in fact that first sqlexecute probably gives an error that you dont appear to check for

  10. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...
    self.DatabaseName = gsDatabaseName 
    self.Password = gsPassword 
    self.UserName =  gsUserName 
    self.Port = gnDBPort  
    self.Host = gsHost 
    
    if self.Connect = false then
      'self = nil
      MsgBox(self.ErrorMessage)
      return false
    end
    
    self.SQLExecute("Set NameS 'utf8'")
    
  11. Richard A

    Feb 10 Pre-Release Testers, Xojo Pro Puerto Vallarta Mexico

    Norman,

    I moved that to after connect, now it loads!

    I'm an idiot!

  12. Kem T

    Feb 10 Pre-Release Testers, Xojo Pro, XDC Speakers, MVP Connecticut

    Sometimes it just takes another pair of eyes.

  13. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...

    Hitting wheel with hammer - $100
    Knowing where to hit the wheel with the hammer - $10,000 :)

  14. Anthony M

    Feb 10 Pre-Release Testers, Xojo Pro Orlando, Florida

    Finding someone who knows where to hit the wheel - priceless

or Sign Up to reply!