Reputation: 8004
I have this procedure
CREATE DEFINER=`ShrinxUser`@`%` PROCEDURE `AddRec`(IN `p_App` VARCHAR(255) CHARSET utf8, IN `p_Code` VARCHAR(255) CHARSET utf8, IN `p_DT` DATETIME, IN `p_IP` VARCHAR(255) CHARSET utf8, IN `p_Field` VARCHAR(255) CHARSET utf8, IN `p_Value` VARCHAR(4000) CHARSET utf8)
BEGIN
INSERT INTO Rec (App, Code, DT, IP, Field, Value)
VALUES (p_App, p_Code, p_DT, p_IP, p_Field, p_Value);
End
When I call it like this
Call AddRec('Test','2399399','12 May 20', ':::1','sss','أكرم');
I get arabic text fine in the database
but when I call it from C# asp.net I get ????
I debugged my C# asp.net code and I noticed that C# reads the arabic text fine.
It sends it in arabic but stored in DB as ?????
here is my C# code
//First Name
cmd.Parameters.Add(new MySqlParameter("p_App", "Test"));
cmd.Parameters.Add(new MySqlParameter("p_Code", "1345"));
cmd.Parameters.Add(new MySqlParameter("p_DT", "20 mar 2020"));
cmd.Parameters.Add(new MySqlParameter("p_IP", "1234"));
cmd.Parameters.Add(new MySqlParameter("p_Field", "Name"));
cmd.Parameters.Add(new MySqlParameter("p_Value", "محمد"));
cmd.CommandType = System.Data.CommandType.StoredProcedure;
if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}
cmd.ExecuteNonQuery();
How to fix that?!
Upvotes: 0
Views: 1298
Reputation: 28162
Add CharSet=utf8mb4
to your connection string to make sure that UTF-8 is used to send data to and from the database. (MySQL Server frequently has latin1
as the default character set, and it can't express non-Latin characters.)
Better yet, update to MySqlConnector, which always uses UTF-8 to transmit data (and fixes many other bugs).
Also use utf8mb4
instead of utf8
wherever you can; MySQL's utf8
is not actually UTF-8 and will lose data (e.g., if trying to store emoji characters).
Upvotes: 1