[Tutorial] How to connect MySQL database in Xamarin.Android / iOS

Example Source Code

In order to connect to mysql, you need download the MySql connector from the below link :
http://dev.mysql.com/downloads/connector/net/
You should use MySql.Data.cf.dll to connect MySQL, instead of using MySql.Data.dll .

The MySql.Data.CF.dll has some problem in compile phase.

It show the following error message.

Reference Required to assembly 'System, Version=2.0.0.0, Culture=neutral, PublickeyToken=969bd8053d3322ac, Retargetable=Yes' containing the base class 'System.ComponentMode.Component'

However, You can path the dll file to make a workaround for this issue.

MySql.Data.CF (Path By SnowWolf725)

(Password: ShareBySnowWolf725)

In the runtime phase, you will get another error message.

Encoding name 'Windows-1252' not supported Parameter name: name

You need add “I18N.West ” into your reference, and add following code into your source code.

new I18N.West.CP1250 ();

new I18N.West.CP1250 ()

It is a workaround for Xamarin bug.

The default character set of mysql connector is cp1250.

So you need add “I18N.West ” into your reference.

http://developer.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization/

However, In some version of Xamarin studio, It didn’t work.

Xamarin didn’t add I18N.West.dll into your IPA file.

So you need add new I18N.West.CP1250 () in your source code to hint Xamarin to add the dll into IPA file.

(If yours Xamarin studio will automatically add I18N.West.dll into your IPA file, you don’t need add this line).

For bypassing the dependency of system.data 2.0.0.0 .

You can use Ildasm to disassembler the dll file.

msdn.microsoft.com/en-us/library/f7dy01k1%28v=vs.110%29.aspx

It can convert the DLL file into IL file.

You can modify the IL source to let it depend on system.data 2.0.5.0 .

After you modify the IL file, you can use ilasm to convert IL file into dll file.

msdn.microsoft.com/en-us/library/496e4ekx%28v=vs.110%29.aspx