I am trying to connect my Xamarin Forms app to MySQL but getting an error.
Steps I have followed
1. Create Xamarin Cross-Platform Mobile App in Visual Studio 15.8.5 using NetStandard.
2. Installed MySQL.Data from NuGet Package Manager.
3. Created following Code in CS file
using MySql.Data.MySqlClient;
using System;
using Xamarin.Forms;
namespace App4
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
TestDatabaseConnection();
}
public void TestDatabaseConnection() { string ConnectionString = "server=ip ;uid=username;port=3306;pwd=password;database=dbname;"; MySqlConnection cConn = new MySqlConnection(ConnectionString); try { cConn.Open(); cConn.Close(); lbl.Text = "Connected"; } catch (Exception ex) { lbl.Text = "Not Connected ..."; txt.Text = ex.Message; } }
}
- I have also checked the database connectivity in Android Emulator which was successful.
- I am getting the following error.
The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
Need Quick Support