MySQL :: Connector / Net Euro Sign

My MySQL database can store the euro symbol just fine (as I tested with my own MySQL client (HeidiSQL)). But with a MySQL.NET connection that uses an ASP.NET application, I cannot insert or read it from the database: am I only getting? rear sign. What could be the possible reason?

+4
source share
6 answers

I would suggest explicitly specifying the encoding in your connection string:

Server = local; Database = schema, Uid = Foo; PWD = bar; CharSet = utf8

It usually solves most of the encoding issues with MySQL Connector / NET.

+5
source

I would say that the MySQL.NET connector sets some mapping-related environment variables on connection; Compare the output of these queries with both HeidiSQL and .NET:

SHOW VARIABLES LIKE "character_set_%"; SHOW VARIABLES LIKE "collation_%"; 

They should all contain utf8-something. If not, you can change them at runtime as in the manual .

+2
source

The following .Net command can encode them for your database and then decode them to the original character ...

 System.Web.HttpUtility.HtmlEncode() System.Web.HttpUtility.HtmlDecode() 
0
source

Presumably you are inserting the euro sign into the field that is entered as NVARCHAR, or you will not be able to correctly insert and receive the euro sign with other customers?

Do you use the correct syntax in your SQL statements to insert and retrieve Unicode data?

To do this, you must use the N specifier character before any string that is unicode, or it will be seamlessly converted to single-byte encoding and become an unreadable character, for example.

 //Inserting Unicode data MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "INSERT INTO SOME_TABLE (someField) VALUES (N'@text')"; cmd.Parameters.Add("text", "Some Unicode Text"); cmd.Connection = conn; cmd.ExecuteNonQuery(); //Selecting Unicode data MySqlCommand select = new MySqlCommand(); select.CommandText = "SELECT * FROM SOME_TABLE WHERE someField=N'@text'"; cmd.Parameters.Add("text", "Some Unicode Text"); cmd.Connection = conn; //Execute your query and process your Results... 
0
source

I had a similar problem when trying to import data from Sybase 12.5 into MS SQL Server 2005.

Basically, MSSQL stores euro and euro signs in vararch if they are encoded correctly, which is great, but I did not understand that Sybase displays data as windows-1252 (Western European), and not UTF-8, and this led to the fact that the data , such as E and the euro symbol, have been translated by the import program as "?". By telling the import program that the input is encoded as 1252, the problem is fixed.

If you encode the output from DB as 1252, when you read it, you should get the correct characters.

For instance:

 System.Text.Encoding enc = System.Text.Encoing.GetEncoding(1252); MySqlDataReader msdr = command.ExecuteReader(); while(msdr.Read()) { ... string val = enc.GetString(enc.GetBytes(msddr.GetString(mssdr.GetOrdinal("varhcar_field")))); ... } 
0
source

Have you set the encoding on the output page correctly? that is, something like <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> or charset=iso-8859-15 , but not charset=iso-8859-1

-one
source

All Articles