{"action":"created","issue":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/2207","repository_url":"https://api.github.com/repos/npgsql/npgsql","labels_url":"https://api.github.com/repos/npgsql/npgsql/issues/2207/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/npgsql/issues/2207/comments","events_url":"https://api.github.com/repos/npgsql/npgsql/issues/2207/events","html_url":"https://github.com/npgsql/npgsql/issues/2207","id":373793011,"node_id":"MDU6SXNzdWUzNzM3OTMwMTE=","number":2207,"title":"Client encoding (LATIN2) set in ConnectionString causes exception","user":{"login":"pospieszja","id":12588082,"node_id":"MDQ6VXNlcjEyNTg4MDgy","avatar_url":"https://avatars2.githubusercontent.com/u/12588082?v=4","gravatar_id":"","url":"https://api.github.com/users/pospieszja","html_url":"https://github.com/pospieszja","followers_url":"https://api.github.com/users/pospieszja/followers","following_url":"https://api.github.com/users/pospieszja/following{/other_user}","gists_url":"https://api.github.com/users/pospieszja/gists{/gist_id}","starred_url":"https://api.github.com/users/pospieszja/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pospieszja/subscriptions","organizations_url":"https://api.github.com/users/pospieszja/orgs","repos_url":"https://api.github.com/users/pospieszja/repos","events_url":"https://api.github.com/users/pospieszja/events{/privacy}","received_events_url":"https://api.github.com/users/pospieszja/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-25T06:31:07Z","updated_at":"2018-11-20T16:17:31Z","closed_at":null,"author_association":"NONE","body":"### Steps to reproduce\r\n```c#\r\n\r\nusing Npgsql;\r\nusing System;\r\nusing System.Data;\r\n\r\nnamespace PGSQLError\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            var sql = \"select nazwa_indeksu from g.gm_kartoteki;\";\r\n\r\n\r\n            var conn = new NpgsqlConnection(\"User ID=postgres;Host=192.168.1.26;Port=5432; Client Encoding = latin2; Database=dbtest;Pooling=true;\");\r\n            conn.Open();\r\n\r\n            using (var cmd = new NpgsqlCommand(sql, conn))\r\n            {\r\n                var reader = cmd.ExecuteReader();\r\n                if (reader.HasRows)\r\n                {\r\n                    while (reader.Read())\r\n                    {\r\n                        Console.WriteLine(reader[\"nazwa_indeksu\"]);\r\n                    }\r\n                    reader.Close();\r\n                }\r\n            }\r\n            conn.Close();\r\n\r\n            Console.ReadKey();\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n### The issue\r\nWhen in connection string I'm using `Client Encoding = latin2` then I get exception. I need to use this option, because database was created in LATIN2 (it's legacy database, i can't format it to UTF8).\r\n\r\nDatabase field called `nazwa_indeksu` may contain polish characters. So whitout this option I get eg.:\r\n- return: MĽKA\r\n- should return: MĄKA (expected value whitout exception)\r\n\r\nLegacy application which using this database on daily business is connecting through ODBC drivers. In ODBC drivers configuration is added `set client_encoding to 'latin2';`.\r\n\r\n\r\n```\r\nException message:\r\nSystem.Text.DecoderFallbackException: 'Unable to translate bytes [AF] at index 28 from specified code page to Unicode.' \r\n\r\nStack trace:\r\n   at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)\r\n   at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)\r\n   at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes)\r\n   at System.Text.UTF8Encoding.GetCharCount(Byte* bytes, Int32 count, DecoderNLS baseDecoder)\r\n   at System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding)\r\n   at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)\r\n   at Npgsql.NpgsqlReadBuffer.ReadString(Int32 byteLen) in C:\\projects\\npgsql\\src\\Npgsql\\NpgsqlReadBuffer.cs:line 349\r\n   at Npgsql.TypeHandlers.TextHandler.Read(NpgsqlReadBuffer buf, Int32 byteLen, Boolean async, FieldDescription fieldDescription) in C:\\projects\\npgsql\\src\\Npgsql\\TypeHandlers\\TextHandler.cs:line 82\r\n   at Npgsql.TypeHandling.NpgsqlTypeHandler`1.Read[TAny](NpgsqlReadBuffer buf, Int32 len, FieldDescription fieldDescription) in C:\\projects\\npgsql\\src\\Npgsql\\TypeHandling\\NpgsqlTypeHandler`.cs:line 114\r\n   at Npgsql.TypeHandling.NpgsqlTypeHandler`1.ReadAsObject(NpgsqlReadBuffer buf, Int32 len, FieldDescription fieldDescription) in C:\\projects\\npgsql\\src\\Npgsql\\TypeHandling\\NpgsqlTypeHandler`.cs:line 120\r\n   at Npgsql.NpgsqlDefaultDataReader.GetValue(Int32 ordinal) in C:\\projects\\npgsql\\src\\Npgsql\\NpgsqlDefaultDataReader.cs:line 176\r\n   at PGSQLError.Program.Main(String[] args) in C:\\Projects\\PGSQLError\\PGSQLError\\Program.cs:line 24\r\n```\r\n\r\n### Further technical details\r\n\r\nNpgsql version: 4.0.3\r\nPostgreSQL version: 9.4.3\r\nOperating system: Database on Linux Debian. Application is running on Windows 10 x64\r\n\r\nOther details about my project setup:\r\nAbove code is written using .NET Core 2.1\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/comments/440332193","html_url":"https://github.com/npgsql/npgsql/issues/2207#issuecomment-440332193","issue_url":"https://api.github.com/repos/npgsql/npgsql/issues/2207","id":440332193,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDMzMjE5Mw==","user":{"login":"roji","id":1862641,"node_id":"MDQ6VXNlcjE4NjI2NDE=","avatar_url":"https://avatars0.githubusercontent.com/u/1862641?v=4","gravatar_id":"","url":"https://api.github.com/users/roji","html_url":"https://github.com/roji","followers_url":"https://api.github.com/users/roji/followers","following_url":"https://api.github.com/users/roji/following{/other_user}","gists_url":"https://api.github.com/users/roji/gists{/gist_id}","starred_url":"https://api.github.com/users/roji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roji/subscriptions","organizations_url":"https://api.github.com/users/roji/orgs","repos_url":"https://api.github.com/users/roji/repos","events_url":"https://api.github.com/users/roji/events{/privacy}","received_events_url":"https://api.github.com/users/roji/received_events","type":"User","site_admin":false},"created_at":"2018-11-20T16:17:31Z","updated_at":"2018-11-20T16:17:31Z","author_association":"MEMBER","body":"I think I overlooked something... Can you still specify `Encoding=LATIN2` in your connection string, in addition to `Client Encoding=LATIN2`? The former is what controls the encoding used when actually decoding strings coming from PostgreSQL (the latter simply sets the PostgreSQL `client_encoding` parameter)."}}
{"actor":{"display_login":"roji"}}