473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

UTF8/Unicode database access query

This is one of those issues that doesn't clearly fit into a single category
as it's both a C# and a database (mySql) issue.

I want to INSERT and SELECT text in UTF8 from a C# application to mySql.

My database character set is UTF8. I am using the native .NET provider from
mysql.com. Everything is at the current version.

My C# code for INSERT looks like this:

cmdMySql.CommandText = "INSERT INTO tblCommunity (Details) VALUES
(?Details)";
MySqlParameter P = new MySqlParameter();
P.MySqlDbType = MySqlDbType.String;
P.ParameterName = "?Details";
P.Value = "Any Russian text string";
cmdMySql.Parameters.Add(P);
cmdMySql.ExecuteNonQuery();

This works, but my Unicode text (Russian) ends up as ???????????????????? in
the database. When I'm in the C# debugger, I can see the Russian text as I
step through the code. So I know my problem is somewhere in how I'm passing
the data to the database. I have also tried a vanilla INSERT statement with
no parameters. It also gives me ??????????? for the Russian text. And if
my string mixes English and Russian, the English text is fine.

Does anyone have any ideas as to what I'm doing wrong?

Thanks.

Bob
Nov 16 '05 #1
4 6047
Bob Sillett <si***************@ABCREMOVE.yahoo.com> wrote:
This is one of those issues that doesn't clearly fit into a single category
as it's both a C# and a database (mySql) issue.
Actually, I'm not sure that it's C#-specific at all. .NET-specific
maybe, but not C#. Anyway, that goes for a good number of other
questions here, so on we go...
I want to INSERT and SELECT text in UTF8 from a C# application to mySql.

My database character set is UTF8. I am using the native .NET provider from
mysql.com. Everything is at the current version.

My C# code for INSERT looks like this:

cmdMySql.CommandText = "INSERT INTO tblCommunity (Details) VALUES
(?Details)";
MySqlParameter P = new MySqlParameter();
P.MySqlDbType = MySqlDbType.String;
P.ParameterName = "?Details";
P.Value = "Any Russian text string";
cmdMySql.Parameters.Add(P);
cmdMySql.ExecuteNonQuery();

This works, but my Unicode text (Russian) ends up as ???????????????????? in
the database. When I'm in the C# debugger, I can see the Russian text as I
step through the code. So I know my problem is somewhere in how I'm passing
the data to the database. I have also tried a vanilla INSERT statement with
no parameters. It also gives me ??????????? for the Russian text. And if
my string mixes English and Russian, the English text is fine.

Does anyone have any ideas as to what I'm doing wrong?


It sounds like the MySql provider is mucking things up. Is there
anything you can put on the connection string to tell it what character
set to use?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Bob Sillett wrote:
This is one of those issues that doesn't clearly fit into a single category
as it's both a C# and a database (mySql) issue.

I want to INSERT and SELECT text in UTF8 from a C# application to mySql.

My database character set is UTF8. I am using the native .NET provider from
mysql.com. Everything is at the current version.

My C# code for INSERT looks like this:

cmdMySql.CommandText = "INSERT INTO tblCommunity (Details) VALUES
(?Details)";
MySqlParameter P = new MySqlParameter();
P.MySqlDbType = MySqlDbType.String;
P.ParameterName = "?Details";
P.Value = "Any Russian text string";
cmdMySql.Parameters.Add(P);
cmdMySql.ExecuteNonQuery();

This works, but my Unicode text (Russian) ends up as ???????????????????? in
the database. When I'm in the C# debugger, I can see the Russian text as I
step through the code. So I know my problem is somewhere in how I'm passing
the data to the database. I have also tried a vanilla INSERT statement with
no parameters. It also gives me ??????????? for the Russian text. And if
my string mixes English and Russian, the English text is fine.

Does anyone have any ideas as to what I'm doing wrong?


Are you sure you're using a MySQL server version (>= 4.1)
with UTF-8 support? You also need a quite up-to-date .NET
mysql-connector (ByteFX.Data) >= 0.9.

bye
Rob
Nov 16 '05 #3
Hi, Jon.

I cannot find any connection string options for character set. But that
doesn't mean that one doesn't exsit. As with many open source programs,
documentation tends to lag behind the actual code. For example, there is a
connection string option to enable ZIP-based compression. It's not listed
in the documentation, but is supported.

My main purpose to posting to this group was to see if I was doing something
fundamentally wrong in C# with the Unicode data. That is, if I needed to
run a text encoder or something.

I'll see what I can come up with in the mySql groups.

Thanks again.

Bob


Nov 16 '05 #4
Bob Sillett <si***************@ABCREMOVE.yahoo.com> wrote:
I cannot find any connection string options for character set. But that
doesn't mean that one doesn't exsit. As with many open source programs,
documentation tends to lag behind the actual code. For example, there is a
connection string option to enable ZIP-based compression. It's not listed
in the documentation, but is supported.

My main purpose to posting to this group was to see if I was doing
something fundamentally wrong in C# with the Unicode data. That is,
if I needed to run a text encoder or something.
You really shouldn't need to, no. If you do, it's a definite deficiency
in the provider.
I'll see what I can come up with in the mySql groups.


Righto. If you could post back here to let us know what happens, I'd be
grateful - I've heard about similar problems before, but haven't heard
the answer...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sinasalek | last post by:
i have a problem with MySQL 4.1.x and UTF8. in version 4.0, i'm using html forms with utf8 charset for inserting unicode strings. but in version 4.1.x it is not working! if i change the charset of...
5
by: Richard Lewis | last post by:
Hi there, I'm having a problem with unicode files and ftplib (using Python 2.3.5). I've got this code: xml_source = codecs.open("foo.xml", 'w+b', "utf8") #xml_source = file("foo.xml",...
6
by: Spamtrap | last post by:
I only work in Perl occasionaly, and have been searching for a solution for a conversion, and everything I found seems much too complex. All I need to do is take a simple text file and copy...
3
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a...
16
by: Greg Miller | last post by:
I have an application that uses sqlite3 to store job/error data. When I log in as a German user the error codes generated are translated into German. The error code text is then stored in the db....
11
by: beachboy | last post by:
Hello all, I am building a CMS which has 2 language: English & Traditional Chinese my problem is all data are represent as "?????????", all pagecode are set to utf8 do I need to encoding(->...
3
by: Joshua Morgan | last post by:
Hey, Currently me and a friend are coding up a new BitTorrent tracker. We have a torrents table that has a column called 'info_hash' which contains the info_hash as received by the announce.php...
1
by: Server Applications | last post by:
Hello I am trying to build a system where I can full-text index documents with UTF8 or UTF16 data using Oracle Text. I am doing the filtering in a third-party component outside the database, so...
8
by: Yves Dorfsman | last post by:
Can you put UTF-8 characters in a dbhash in python 2.5 ? It fails when I try: #!/bin/env python # -*- coding: utf-8 -*- import dbhash db = dbhash.open('dbfile.db', 'w') db = u'☺'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.