Bug #33938 CodePage 1252 is not supported on Mono/.Net
Submitted: 19 Jan 2008 14:16 Modified: 6 Jun 2008 7:06
Reporter: Rajko Horvat Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.1.4 OS:Any
Assigned to: CPU Architecture:Any

[19 Jan 2008 14:16] Rajko Horvat
Description:
This bug reproduces on recent Mono/.NET distribution.
The problem is in Connector for .NET version 5.1.4, which is publicly available for download.

I hope this resolution helps.

Best regards,
Rajko Horvat

How to repeat:
Just try to open the connection to the database under Mono/.NET.

I traced the problem in source code to the constructor of the Driver class in Driver.cs

The problem is produced by the following line:
encoding = Encoding.GetEncoding(1252);

The code page 1252 is not available on Mono 1.2.6.

Suggested fix:
// old code commented out
//encoding = Encoding.GetEncoding(1252);
// end old code commented out

// added code - resolves issue CodePage 1252 not found on Mono/.NET
try
{
	encoding = Encoding.GetEncoding(1252);
}
catch (NotSupportedException)
{
	encoding = Encoding.GetEncoding(0);
}
// end added code
[23 Jan 2008 14:01] Brett Kiefer
We are seeing this with Mono 1.2.6 from backports on Debian Etch, and it appears that the workaround is to install the mono-i18n package.
[23 Jan 2008 14:12] Rajko Horvat
Yes, but, that way you limit yourself to a certain code page, isn't it that driver should work regardless of code page used? So installing mono-i18n package is a workaround, and not a definite fix. I proposed a fix that should solve the problem regardless of code page.
[25 Jan 2008 16:52] Tonci Grgin
Hi Rajko and thanks for your report. I am puzzled here, are you notifying me of mono bug or trying to say this is something MySQL can / should fix?
[28 Jan 2008 9:30] Rajko Horvat
Well, I think this is something that should be fixed, the fix that I proposed should handle situation when code page 1252 isn't available. I tested connector with default code page instead of code page 1252 and everything is working fine.

Hope that helps.
[5 Feb 2008 12:11] Tonci Grgin
Rajko, I will need some help here... On Win Encoding is part of System.Text, not so in mono... So, I would like to have complete test case I can import into mono-develop or Eclipse on my linux box.
[11 Feb 2008 12:18] Rajko Horvat
I'm sorry I am not using mono-develop or eclypse so I can't help you on that.
I compile executable directly with mono compiler and do the developing with Visual studio.

Best regards,
Rajko
[11 Feb 2008 12:33] Rajko Horvat
Test case:
----------------------------------------------------------------------------
using System;
using System.IO;
using System.Data;
using MySql.Data.MySqlClient;

public class TestCase
{
	[STAThread]
	static void Main(string[] args)
	{
		// Create our connection and command objects
		string sUser = "root";
		string sPassword = "password";
		MySqlConnection oConnection;

		try
		{
			oConnection =
				new MySqlConnection("Persist Security Info=False;database=Sample;server=localhost;user id=" + sUser + ";pwd=" + sPassword);
			oConnection.Open();
		}
		catch (Exception ex)
		{
			Console.WriteLine("Can't connect to database.\nException: {0}", ex.ToString());
			return;
		}

		try
		{
			MySqlDataAdapter oAdapter = new MySqlDataAdapter("select * from Projects", oConnection);
			DataTable oProjects = new DataTable("Projects");
			oAdapter.Fill(oProjects);

			oProjects.Dispose();
			oAdapter.Dispose();
		}
		catch (Exception ex)
		{
			Console.WriteLine("Exception: {0}", ex.ToString());
		}

		try
		{
			oConnection.Close();
		}
		catch
		{ }
	}
}
[11 Feb 2008 13:15] Tonci Grgin
Rajko, thanks for the test case provided. I'll try and find out what's happening. I'm glad Rudjer uses MySQL too ;-)
[25 Feb 2008 20:03] Reggie Burnett
This is not a bug.  I  conferred with our other connector people and they agree with me.  Proceeding with a charset different than the requested one is dangerous.  It's possible to corrupt your database that way.
[5 Jun 2008 10:19] glyn h
Rajko - I just wanted to thank you for posting this.  I am a linux newbie, and this really had me stumped.  At the end of my second frustrating evening, I came across your post.
Thanks to all who contributed, without this, I wouldn't have known that I needed to install libmono-i18n1.0-cil package to fix the problem.  
Regards,
Glyn.
[5 Jun 2008 12:43] Tonci Grgin
Hi Glyn. That's what's BugsDB is about :-)

Thanks for your interest in MySQL.
[6 Jun 2008 7:06] Rajko Horvat
You're welcome! When I had this problem I couldn't find any solution,
and believe me I searched everywhere.
And this is why I reported this as a bug, so that other people with this or similar problem could find the solution. :)
[11 Jun 2008 6:31] Tonci Grgin
Rajko, great work and it's much appreciated. I know there are hundreds not posting to this page who read it carefully.

Thanks for your interest in MySQL.