Search code examples
c#.netencodingodbcteradata

Teradata .Net ODBC provider encoding issues


I am loading data with Teradata .Net ODBC provider which works quite well, but when I load string for Japanese/Chinese or other languages that require are not in ASCII encoding I just get the substitute character (/u0001). So is there any possibility to setup the driver to return the data in UTF8? I also check the DB itself and the data are correctly stored with all not ASCII characters.

Code example I use:

using var cn = new TdConnection(connectionString);
        cn.Open();

        TdCommand cmd = cn.CreateCommand();
        cmd.CommandTimeout = 3600;
        cmd.CommandText = query;

        using var reader = cmd.ExecuteReader();
        if (reader.HasRows)
        {
            while (reader.Read())
            {
                var test = reader.GetString(reader.GetOrdinal("description"));

                ...other fields
            }
        }

        cn.Close();

Solution

  • So at the end the correct working code is this:

    var builder = new TdConnectionStringBuilder(connectionString)
            {
                SessionCharacterSet = "UTF8"
            };
    
    using var cn = new TdConnection(builder.ConnectionString);
    cn.Open();
    

    TdConnection do not accept anything else than string so TdConnectionStringBuilder is needed for additional properties.