I'm upgrading a program for work that uses postgres 9.2.4. When the program is run for the first time, it creates a production database, using the existing template database. The program used to run with postgres 8, which uses sql_ascii for its client encoding. Postgres 9 uses UTF8.

I know how to fix this on the command line by changing the template database's encoding to sql_ascii, but ideally I'd like to figure out how to get the program to create the new database using the new UTF8 encoding.

I found this line in the program

sqlString = "CREATE DATABASE " & m_sProdDBName & " WITH OWNER=" & _
m_s4 & " TEMPLATE=" & m_s5 & " ENCODING='sql_ascii' LOCATION= DEFAULT;" 

And I changed sql_ascii to UTF8.

However, the 'Client encoding mismatch' error gets thrown before that line ever gets executed. It happens when the connection to the template DB is being created. I got a message box to pop up with the connection string right before the connection opens. For some reason, it is hitting the messagebox code twice, even though it should only hit it once. The first time, no connection attempt is made. The second time the program goes on and attempts to open the connection, which is when the error gets thrown. Here are the two connection strings:



(I know that no password is needed so that isn't the problem). Remindex is the database to be created and template1 is the template DB.

In case you need some additional information, the connection object is an ADODB.Connection object and the Provider is MSDASQL.

I'm not all that good with database stuff, so I apologize for my lack of knowledge.

Any suggestions would be greatly appreciated!

1 Answer 1


Client Encoding Mismatch is an error message from old versions of the PostgreSQL ODBC driver.

You should go here: http://www.postgresql.org/ftp/odbc/versions/msi/ to get the most recent version and update your system.

Also there are in fact two driver flavors that get installed: ANSI and Unicode. Presumably you need Unicode if you decided to switch to utf-8.

  • Thanks for the reply! I updated the ODBC driver and the error went away, but now my program doesn't seem to want to connect to the database service. It creates the DB fine however. I was getting an error at some point saying something like 'OLE DB error : unable to send query to the backend', but I'm not getting that anymore. It simply isn't connecting. Commented Sep 8, 2013 at 22:53
  • Perhaps I should clarify a little. I can retrieve information fine from the database, as I can see all of my settings in the program (which are stored in the DB). However, the program communicates with a service which connects to postgres, and that is what I can't connect to. I'm getting a message saying 'connection forcefully rejected'. Both the postgres service and the custom service are started. I'm sorry if this is all a bit unclear, but like I said earlier, I'm no database expert. Commented Sep 8, 2013 at 23:00
  • I posted a new question on this issue here : dba.stackexchange.com/q/49481/24413 . Please take a look if you have the time! Even some tips on troubleshooting would be extremely helpful. Commented Sep 13, 2013 at 3:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.