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

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.

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

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.

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.

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

I can’t get it out.

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

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

I open the DB with:

[code]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

[/code]

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


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'")

Norman,

I moved that to after connect, now it loads!

I’m an idiot!

Sometimes it just takes another pair of eyes.

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

Finding someone who knows where to hit the wheel - priceless