Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

I have tried everything to get my Mac app to connect to MySQL.

kelison73kelison73 Member ✭✭
edited December 2017 in Xamarin.iOS

I have MySql.Data.dll version 6.10.5.0 installed and selected in the .Net Assembly tab:

Here is my code:

using System;
using AppKit;
using Foundation;
using MySql;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace Mysqlteest
{
    public partial class ViewController : NSViewController
    {
        public ViewController(IntPtr handle) : base(handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            string connectionString =
                   @"Server=127.0.0.1;" +
                @"Port=3306;" +
                   @"User ID=root;" +
                   @"Password=************;" +
                   @"Database=Career Progress;" +
                @"Pooling=false;";

            //      Now we make the connection.

            MySqlConnection mySqlConnection = new MySqlConnection();
            mySqlConnection.ConnectionString = connectionString;

            //      The Open method works!
            //      And the Open method fails correctly when wrong credentials are used.
            mySqlConnection.Open();
            mySqlConnection.Close();

            // Do any additional setup after loading the view.
        }

It will throw an exception on the mySqlConnection.Open(); I am just trying a test app to see if I can get it to work.

No matter what I try I can not get it to work.

Help Please.

Tagged:

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    This is what I would try:

    • First, create a .net console application and try there. If that fails, then you can dig into your sql server and/or the library and know that it isn't related to Xamarin.Mac at all.
    • If in the rather unlikely event that it works there but not in XM, I would try using the Full target framework (https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/) to see if it acts more like the .Net console version.
  • kelison73kelison73 Member ✭✭

    Here is the exception:

    System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.data. (/Users/kelison/Projects/Mysqlteest/Mysqlteest/bin/Debug/Mysqlteest.app/Contents/MonoBundle/Mysqlteest.exe.config line 3)
    at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors (System.Boolean ignoreLocal) [0x00029] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors (System.Configuration.ConfigurationSchemaErrors schemaErrors) [0x00011] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors () [0x00000] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ClientConfigurationSystem.EnsureInit (System.String configKey) [0x000be] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    --- End of inner exception stack trace ---
    at System.Configuration.ClientConfigurationSystem.EnsureInit (System.String configKey) [0x00109] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem (System.String sectionName) [0x00008] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String sectionName) [0x00000] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00011] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at MySql.Data.MySqlClient.MySqlConfiguration..cctor () [0x00000] in :0
    --- End of inner exception stack trace ---
    at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor () [0x0001e] in :0
    --- End of inner exception stack trace ---
    at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in :0
    at Mysqlteest.ViewController.ViewDidLoad () [0x0001c] in /Users/kelison/Projects/Mysqlteest/Mysqlteest/ViewController.cs:37
    at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
    at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/5489/c4240f3f/source/xamarin-macios/src/AppKit/NSApplication.cs:100
    at Mysqlteest.MainClass.Main (System.String[] args) [0x00007] in /Users/kelison/Projects/Mysqlteest/Mysqlteest/Main.cs:13

  • kelison73kelison73 Member ✭✭

    Here is the exception:

    System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section system.data. (/Users/kelison/Projects/Mysqlteest/Mysqlteest/bin/Debug/Mysqlteest.app/Contents/MonoBundle/Mysqlteest.exe.config line 3)
    at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors (System.Boolean ignoreLocal) [0x00029] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors (System.Configuration.ConfigurationSchemaErrors schemaErrors) [0x00011] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors () [0x00000] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ClientConfigurationSystem.EnsureInit (System.String configKey) [0x000be] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    --- End of inner exception stack trace ---
    at System.Configuration.ClientConfigurationSystem.EnsureInit (System.String configKey) [0x00109] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem (System.String sectionName) [0x00008] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String sectionName) [0x00000] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00011] in <4cd8a957e7664f4a9e27ce43dd1afeb7>:0
    at MySql.Data.MySqlClient.MySqlConfiguration..cctor () [0x00000] in :0
    --- End of inner exception stack trace ---
    at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor () [0x0001e] in :0
    --- End of inner exception stack trace ---
    at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in :0
    at Mysqlteest.ViewController.ViewDidLoad () [0x0001c] in /Users/kelison/Projects/Mysqlteest/Mysqlteest/ViewController.cs:37
    at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
    at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/5489/c4240f3f/source/xamarin-macios/src/AppKit/NSApplication.cs:100
    at Mysqlteest.MainClass.Main (System.String[] args) [0x00007] in /Users/kelison/Projects/Mysqlteest/Mysqlteest/Main.cs:13

  • kelison73kelison73 Member ✭✭

    @ChrisHamons I created a console and and that worked but still can't get it to work with a Mac app.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @kelison73

    Did you try to change the Xam.Mac target framework as Chris suggested in the case that the console app worked but the Xam.Mac app did not?

  • kelison73kelison73 Member ✭✭

    @JGoldberger

    Yes I did do that. I did create a console app that worked just fine. Then I went back and created a new Mac app and changed the target framework to full. It did nothing.

  • JassimRahmaJassimRahma USMember ✭✭✭✭

    I am getting the same error.

    Any solution?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    I would contact the supplier of your SQL provider for support. No one here is likely an expert at MySQL.

Sign In or Register to comment.