Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Xamarin Form Cross Platform App MySQL Database Connectivity Error

$
0
0

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;
              }
        }

}

  1. I have also checked the database connectivity in Android Emulator which was successful.
  2. I am getting the following error.

The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.

Need Quick Support


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>