1

I've got a PostgreSQL database that uses the UTF8 encoding. I believe this is the default encoding.

I've got a GUI application that issues a typical SELECT query, with a WHERE clause. The query is parameterized, and the content of the parameter is usually pasted in by the end user. The value is not read from a text file, etc - it's pasted into a memo edit.

Here is the query ...

cmd.CommandText = @"SELECT history_id, emplid, displayname
                    FROM ""MAX_HISTORY_IDS""
                    WHERE searchname ILIKE :searchname";

cmd.Parameters.Add("searchname", PgSqlType.VarChar).Value = "Sievert,Jürgen";

In the above code, the parameter value, Sievert,Jürgen, would be a variable parsed out of a memo edit box, or text input, etc. That name is also a real example of a name causing this query to result in an invalid UTF8 byte sequence error, from Postgre.

Now, I assume the UTF8 encoding, on the database, is fine and is pretty standard for this kind of content. What's wrong here? Is the encoding of this text parameter not UTF8? How can I get this query to work, or is the encoding on the database not suitable?

1 Answer 1

1

I figured it out. I'm using the DotConnect PostgreSQL client library. In the connection string I simply needed to add Unicode=True. This seems to make everything work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.