Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL 17.2 Npgsql development string garbled #219

Open
roxxxxssss opened this issue Dec 18, 2024 · 5 comments
Open

PostgreSQL 17.2 Npgsql development string garbled #219

roxxxxssss opened this issue Dec 18, 2024 · 5 comments

Comments

@roxxxxssss
Copy link

hello, I am using the postgresql-17.2-2-windows-x64.exe installation package, my operating system is Win11 24H2, My development tool is Microsoft Visual Studio Community 2022 (64 位) 17.12.3, The project engineering is the blazor web app (Server Mode),

My operating system environment is Simplified Chinese.

When installing, I encountered the 'Locale' option and chose 'Default Locale'.

Locale : Default locale

My Home.razor code :

@page "/"

@using Npgsql

Home

Hello, world!

Welcome to your new app.

<button class="btn btn-primary" @OnClick="IncrementCount">Click me

@code{
private async void IncrementCount()
{
try{
var connectionString = "Host=127.0.0.1;Username=postgres;Password=mypassword;Database=postgres;Pooling=true;Encoding=UTF8;";

        await using var dataSource = NpgsqlDataSource.Create(connectionString);

        await using (var cmd = dataSource.CreateCommand("INSERT INTO data (some_field) VALUES ($1)"))
        {
            cmd.Parameters.AddWithValue("Hello world");
            await cmd.ExecuteNonQueryAsync();
        }
    }catch (Exception ex){

        string szMessage = ex.Message;
    }
}

}

Exception ex Msg return -> {"28P01: �û� "postgres" Password ��֤ʧ��"}

I used pgAdmin4 to check that the database encoding is UTF8.

SQL :
SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'postgres';

Did I make a mistake in choosing something?Could you please teach me? Thank you

@roxxxxssss
Copy link
Author

Normally, UTF8 supports Simplified Chinese. Is my understanding incorrect ?

@roxxxxssss
Copy link
Author

roxxxxssss commented Dec 18, 2024

Npgsql version : 9.0.2,

I choose Locale : Chinese (Simplified), China, installing Tip : Warning - Problem running post-install step. Installation may not complete correctly The database cluster initialisation failed

@roxxxxssss
Copy link
Author

Only choose -> Locale : [Default locale] can install success.

@roxxxxssss
Copy link
Author

roxxxxssss commented Dec 19, 2024

var connectionString = "Host=127.0.0.1;Username=postgres;Password=mypassword;Database=postgres;Encoding=GB2312;";

Set Encoding=GB2312;

After execution, the prompt is normal.

{"28P01: 用户 "postgres" Password 认证失败"}

@roxxxxssss
Copy link
Author

but, new question : I got garbled again when using GB2312 encoding to execute the Create table statement,

var connectionString = "Host=127.0.0.1;Username=postgres;Password=mypassword;Database=postgres;Encoding=GB2312;";

Create Table Result :

{"42601: 璇硶閿欒 鍦?")" 鎴栭檮杩戠殑\r\n\r\nPOSITION: 1235"}

I changed GB2312 to UTF8 again and it's normal, May I ask which encoding is correct ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant