Mimetis / Dotmim.Sync

A brand new database synchronization framework, multi platform, multi databases, developed on top of .Net Standard 2.0. https://dotmimsync.readthedocs.io/
MIT License
876 stars 187 forks source link

Table does not get created in SQLite database #276

Closed TybbyAce closed 4 years ago

TybbyAce commented 4 years ago

Hi Sebastien,

When I run the sync between a MySql server and a local SQLite in a Xamarin app, the SQLite file gets created with the scope_info table but nothing else. This is what I get back from Progress:

2020-05-12 17:02:03.999341+0100 mysqlconnectorxamarintest.iOS[27606:351926] BeginSession:5:02:03 PM.989 Session Id:c62887a7-5c54-4037-bdd3-957bbe82092f 2020-05-12 17:02:04.046957+0100 mysqlconnectorxamarintest.iOS[27606:351926] ScopeLoaded:5:02:04 PM.46 [main] [DefaultScope] [Version ] Last sync: Last sync duration:0:0:0.0

No error messages at all. ( I can make connection to the MySql database earlier in the code by MySqlConnector, so that can't be the problem this time).

Screen Shot 2020-05-12 at 16 38 51

What am I doing wrong? Thanks a lot for helping me out.



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dotmim.Sync;
using Dotmim.Sync.MySql;
using Dotmim.Sync.Sqlite;
using MySql.Data.MySqlClient;
using Xamarin.Forms;

namespace mysqlconnectorxamarintest
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        private static string serverConnectionString = "server = 127.0.0.1; user id = test; password =test123; persistsecurityinfo = True; database = itemsDB; AllowLoadLocalInfile=true; ConnectionTimeout=10";
        static private readonly string clientPathAndName = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "items.db3");
        public MainPage()
        {
            InitializeComponent();
        }

        protected override void OnAppearing()
        {
            using (MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(serverConnectionString))
            {
                try
                {
                    conn.Open();
                    string sql = "DROP TABLE IF EXISTS `itemsDB`.`T1`  ;CREATE TABLE  `itemsDB`.`T1` ( `Name` VARCHAR(50) NOT NULL  ); INSERT INTO `itemsDB`.`T1` (`Name`) VALUES ('Abracadabra'); ";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("T1 table created, record added");
                    conn.Close();

                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);

                }
            }
        }

        public static async Task SyncDB()
        {
            SQLitePCL.Batteries_V2.Init();

            // Sql Server provider, the "server" or "hub".
            MySqlSyncProvider serverProvider = new MySqlSyncProvider(serverConnectionString);

            // Sqlite Client provider acting as the "client"
            SqliteSyncProvider clientProvider = new SqliteSyncProvider(clientPathAndName);

            // Tables involved in the sync process:
            var tables = new string[] { "T1" };

            // Sync agent
            SyncAgent agent = new SyncAgent(clientProvider, serverProvider, tables);
            var progress = new SynchronousProgress<ProgressArgs>(args => Console.WriteLine($"{args.Context.SyncStage}:{args.Message}"));
            var result =  await agent.SynchronizeAsync(progress);
            Console.WriteLine(result);
        }

        void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            SyncDB();
        }
    }
}
Mimetis commented 4 years ago

You may have a conflict with MySql.Data. See #272

Can you try to remove MySql.Data and try with MySqlConnector instead ?

TybbyAce commented 4 years ago

Only MySqlConnector is installed, Dotmim.Sync.Mysql brought it. It works now, but apart from the sync.

This is what I have installed:

Screen Shot 2020-05-12 at 20 49 16

Mimetis commented 4 years ago

I see that in your code

using MySql.Data.MySqlClient;

et that

using (MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(serverConnectionString))
            {

Where does it come from ?

TybbyAce commented 4 years ago

It must be coming from Mysqlconnector. If I don't use it I can't make a connection to my server. See screenshots.

Thanks

Screen Shot 2020-05-12 at 23 23 52

Screen Shot 2020-05-12 at 23 20 48

Mimetis commented 4 years ago

Oh, yes you're right, my bad...

what is the stack error trace ?

TybbyAce commented 4 years ago

There's no any error, it doesn't crash. It just simply doesn't create the user data table in SQlite, only the scope_info.

Thanks

Mimetis commented 4 years ago

Is it working with a console application, outside xamarin ?

TybbyAce commented 4 years ago

No, it's the same :(

Screen Shot 2020-05-13 at 10 22 28

Screen Shot 2020-05-13 at 10 22 36

Screen Shot 2020-05-13 at 10 24 01


using System;
using System.Threading.Tasks;
using Dotmim.Sync;
using Dotmim.Sync.MySql;
using Dotmim.Sync.Sqlite;
using MySql.Data.MySqlClient;

namespace dotmomsyncconsoletest
{
    class Program
    {
        private static string serverConnectionString = "server = 127.0.0.1; user id = test; password =test123; persistsecurityinfo = True; database = itemsDB; AllowLoadLocalInfile=true; ConnectionTimeout=10";
        static private readonly string clientPathAndName = "/Users/Tibor/items.db3";
        static void Main(string[] args)
        {
            using (MySqlConnection conn = new MySqlConnection(serverConnectionString))
            {
                try
                {
                    conn.Open();
                    string sql = "DROP TABLE IF EXISTS `itemsDB`.`T1`  ;CREATE TABLE  `itemsDB`.`T1` ( `Name` VARCHAR(50) NOT NULL  ); INSERT INTO `itemsDB`.`T1` (`Name`) VALUES ('Abracadabra'); ";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.ExecuteNonQuery();
                    //Console.WriteLine("T1 table created, record added");
                    conn.Close();

                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);

                }
            }
            SyncDB();
        }
        public static async Task SyncDB()
        {
            SQLitePCL.Batteries_V2.Init();

            // Sql Server provider, the "server" or "hub".
            MySqlSyncProvider serverProvider = new MySqlSyncProvider(serverConnectionString);

            // Sqlite Client provider acting as the "client"
            SqliteSyncProvider clientProvider = new SqliteSyncProvider(clientPathAndName);

            // Tables involved in the sync process:
            var tables = new string[] { "T1" };

            // Sync agent
            SyncAgent agent = new SyncAgent(clientProvider, serverProvider, tables);
            var progress = new SynchronousProgress<ProgressArgs>(args => Console.WriteLine($"{args.Context.SyncStage}:{args.Message}"));
            var result = await agent.SynchronizeAsync(progress);
            Console.WriteLine(result);
        }

    }
}
Mimetis commented 4 years ago

Ok we are progressing, I guess... I don't have Xamarin installed, but I can make some tests from a console app.

Can you share your database schema ? I assume your code is the one you shared.

I will make some tests on my own and we will make a comparision

Mimetis commented 4 years ago

Ok, I've got it.

You have multiples errors in your code.

First of all, you can't see any errors raised, because your code is not calling the SyncDB() in an async mode. So far, an error is raised by DMS but since you did not await the method, you can not catch the error...

First things is to change your Main method to

static async Task Main(string[] args)

Then call the SyncDB() correctly :

await SyncDB();

Once it's done, you will get this error raised: image

Obviously, your table needs to have a primary key. So far I've changed the SQL code to:

DROP TABLE IF EXISTS `itemsDB`.`T1`  ;CREATE TABLE  `itemsDB`.`T1` (`Id` int NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50) NOT NULL, PRIMARY KEY (`Id`)  ); INSERT INTO `itemsDB`.`T1` (`Name`) VALUES ('Abracadabra'); 

And then relaunch everything with this result:

Provisioned:11:55:06.228     [main] tables count:1 provision:Table, TrackingTable, StoredProcedures, Triggers
ChangesSelected:11:55:06.249     [main] upserts:0 deletes:0 total:0
ChangesApplying:11:55:06.455     [main] [T1] Modified applied:1 resolved conflicts:0
ChangesApplied:11:55:06.479  [main] applied:1 resolved conflicts:0
EndSession:11:55:06.481  Session Id:d7da177d-50b2-4d9e-9d24-6de7b5325f10
Synchronization done. 
    Total changes  uploaded: 0
    Total changes  downloaded: 1 
    Total changes  applied: 1 
    Total resolved conflicts: 0
    Total duration :0:0:1.616 

My table has been correctly created in Sqlite:

image

image

FYI, here is my full code:


private static string serverConnectionString = "server=127.0.0.1;port=3307;...";
static private readonly string clientPathAndName = "items.db3";
static async Task Main(string[] args)
{
    using (MySqlConnection conn = new MySqlConnection(serverConnectionString))
    {
        try
        {
            conn.Open();
            string sql = "DROP TABLE IF EXISTS `itemsDB`.`T1`  ;CREATE TABLE  `itemsDB`.`T1` (`Id` int NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50) NOT NULL, PRIMARY KEY (`Id`)  ); INSERT INTO `itemsDB`.`T1` (`Name`) VALUES ('Abracadabra'); ";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            //Console.WriteLine("T1 table created, record added");
            conn.Close();

        }
        catch (MySqlException ex)
        {
            Console.WriteLine(ex.Message);

        }
    }
    await SyncDB();
}

public static async Task SyncDB()
{
    SQLitePCL.Batteries_V2.Init();

    // Sql Server provider, the "server" or "hub".
    MySqlSyncProvider serverProvider = new MySqlSyncProvider(serverConnectionString);

    // Sqlite Client provider acting as the "client"
    SqliteSyncProvider clientProvider = new SqliteSyncProvider(clientPathAndName);

    // Tables involved in the sync process:
    var tables = new string[] { "T1" };

    // Sync agent
    SyncAgent agent = new SyncAgent(clientProvider, serverProvider, tables);
    var progress = new SynchronousProgress<ProgressArgs>(args => Console.WriteLine($"{args.Context.SyncStage}:{args.Message}"));
    var result = await agent.SynchronizeAsync(progress);
    Console.WriteLine(result);
}

Seb

TybbyAce commented 4 years ago

You're right in both: Primary index is a must and exception is only thrown when awaited. So, I modified my console app and it works perfectly! However, Xamarin is driving me nuts. Same code, I made the caller async (tried both OnAppearing or Button_click) and awaited the sync process, the darn thing throws an Index out of bounds error. Back to square one :(

What am I doing wrong?

Thanks

Screen Shot 2020-05-13 at 12 31 26 Screen Shot 2020-05-13 at 12 31 59


using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Dotmim.Sync;
using Dotmim.Sync.MySql;
using Dotmim.Sync.Sqlite;
using MySql.Data.MySqlClient;
using Xamarin.Forms;

namespace mysqlconnectorxamarintest
{
    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        private static string serverConnectionString = "server = 127.0.0.1; user id = test; password =test123; persistsecurityinfo = True; database = itemsDB; AllowLoadLocalInfile=true; ConnectionTimeout=10";
        static private readonly string clientPathAndName = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "items.db3");
        public MainPage()
        {
            InitializeComponent();
        }

        protected override async void OnAppearing()
        {
            using (MySqlConnection conn = new MySqlConnection(serverConnectionString))
            {
                try
                {
                    conn.Open();
                    string sql = "DROP TABLE IF EXISTS `itemsDB`.`T1`  ; CREATE TABLE  `itemsDB`.`T1` (`Id` int NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50) NOT NULL, PRIMARY KEY(`Id`)  ); INSERT INTO `itemsDB`.`T1` (`Name`) VALUES('Abracadabra')";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("T1 table created, record added");
                    conn.Close();

                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);

                }
            }
            await SyncDB();
        }

        public static async Task SyncDB()
        {
            SQLitePCL.Batteries_V2.Init();

            // Sql Server provider, the "server" or "hub".
            MySqlSyncProvider serverProvider = new MySqlSyncProvider(serverConnectionString);

            // Sqlite Client provider acting as the "client"
            SqliteSyncProvider clientProvider = new SqliteSyncProvider(clientPathAndName);

            // Tables involved in the sync process:
            var tables = new string[] { "T1" };

            // Sync agent
            SyncAgent agent = new SyncAgent(clientProvider, serverProvider, tables);
            var progress = new SynchronousProgress<ProgressArgs>(args => Console.WriteLine($"{args.Context.SyncStage}:{args.Message}"));
            var result =  await agent.SynchronizeAsync(progress);
            Debug.WriteLine(result);
        }

        private async void Button_Clicked(System.Object sender, System.EventArgs e)
        {

        }

    }
}
Mimetis commented 4 years ago

CAn you copy paste the whole stack trace?

TybbyAce commented 4 years ago

Sure! Thanks.


Dotmim.Sync.SyncException: Index was outside the bounds of the array. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at MySqlConnector.Protocol.PayloadData.get_HeaderByte () [0x00007] in <e1100661ad2449749ae6ce9f9beff904>:0
  at MySqlConnector.Core.ServerSession.ReceiveReplyAsync (MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00076] in <e1100661ad2449749ae6ce9f9beff904>:0
  at MySqlConnector.Core.ServerSession.ReceiveAsync (MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x0000b] in <e1100661ad2449749ae6ce9f9beff904>:0
  at MySqlConnector.Core.ServerSession.ConnectAsync (MySqlConnector.Core.ConnectionSettings cs, System.Int32 startTickCount, MySqlConnector.Core.ILoadBalancer loadBalancer, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x0034d] in <e1100661ad2449749ae6ce9f9beff904>:0
  at MySqlConnector.Core.ConnectionPool.GetSessionAsync (MySql.Data.MySqlClient.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x005eb] in <e1100661ad2449749ae6ce9f9beff904>:0
  at MySqlConnector.Core.ConnectionPool.GetSessionAsync (MySql.Data.MySqlClient.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x007ff] in <e1100661ad2449749ae6ce9f9beff904>:0
  at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
  at MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync (MySqlConnector.Core.ConnectionPool pool, System.Int32 startTickCount, System.Nullable`1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x0016a] in <e1100661ad2449749ae6ce9f9beff904>:0
  at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
  at MySql.Data.MySqlClient.MySqlConnection.OpenAsync (System.Nullable`1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00144] in <e1100661ad2449749ae6ce9f9beff904>:0
  at Dotmim.Sync.SyncPolicy+<>c__DisplayClass11_0.<ExecuteAsync>b__0 () [0x0006d] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  at Dotmim.Sync.SyncPolicy.InternalExecuteAsync[TResult] (System.Func`1[TResult] operation, System.Threading.CancellationToken cancellationToken) [0x00108] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  at Dotmim.Sync.BaseOrchestrator.OpenConnectionAsync (System.Data.Common.DbConnection connection, System.Threading.CancellationToken cancellationToken) [0x0017b] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  at Dotmim.Sync.RemoteOrchestrator.EnsureSchemaAsync (System.Threading.CancellationToken cancellationToken, System.IProgress`1[T] progress) [0x0012d] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  --- End of inner exception stack trace ---
  at Dotmim.Sync.BaseOrchestrator.RaiseError (System.Exception exception) [0x00046] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  at Dotmim.Sync.RemoteOrchestrator.EnsureSchemaAsync (System.Threading.CancellationToken cancellationToken, System.IProgress`1[T] progress) [0x00f0a] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  at Dotmim.Sync.SyncAgent.SynchronizeAsync (Dotmim.Sync.Enumerations.SyncType syncType, System.Threading.CancellationToken cancellationToken, System.IProgress`1[T] progress) [0x00d28] in <d2f8f5ce55ab4a8892c9b514592a8f17>:0
  at mysqlconnectorxamarintest.MainPage.SyncDB () [0x000af] in /Users/Tibor/Projects/mysqlconnectorxamarintest/mysqlconnectorxamarintest/MainPage.xaml.cs:63
  at mysqlconnectorxamarintest.MainPage.OnAppearing () [0x000d1] in /Users/Tibor/Projects/mysqlconnectorxamarintest/mysqlconnectorxamarintest/MainPage.xaml.cs:44
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/Foundation/NSAction.cs:178
  at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:86
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:65
  at mysqlconnectorxamarintest.iOS.Application.Main (System.String[] args) [0x00001] in /Users/Tibor/Projects/mysqlconnectorxamarintest/mysqlconnectorxamarintest.iOS/Main.cs:17
Mimetis commented 4 years ago

Or you able to connect to mysql from xamarin?

Le mer. 13 mai 2020 à 13:55, TybbyAce notifications@github.com a écrit :

Sure! Thanks.

Dotmim.Sync.SyncException: Index was outside the bounds of the array. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array. at MySqlConnector.Protocol.PayloadData.get_HeaderByte () [0x00007] in :0 at MySqlConnector.Core.ServerSession.ReceiveReplyAsync (MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00076] in :0 at MySqlConnector.Core.ServerSession.ReceiveAsync (MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x0000b] in :0 at MySqlConnector.Core.ServerSession.ConnectAsync (MySqlConnector.Core.ConnectionSettings cs, System.Int32 startTickCount, MySqlConnector.Core.ILoadBalancer loadBalancer, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x0034d] in :0 at MySqlConnector.Core.ConnectionPool.GetSessionAsync (MySql.Data.MySqlClient.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x005eb] in :0 at MySqlConnector.Core.ConnectionPool.GetSessionAsync (MySql.Data.MySqlClient.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x007ff] in :0 at System.Threading.Tasks.ValueTask1[TResult].get_Result () [0x0001b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813 at MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync (MySqlConnector.Core.ConnectionPool pool, System.Int32 startTickCount, System.Nullable1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x0016a] in :0 at System.Threading.Tasks.ValueTask1[TResult].get_Result () [0x0001b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813 at MySql.Data.MySqlClient.MySqlConnection.OpenAsync (System.Nullable1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00144] in :0 at Dotmim.Sync.SyncPolicy+<>c__DisplayClass11_0.b__0 () [0x0006d] in :0 at Dotmim.Sync.SyncPolicy.InternalExecuteAsync[TResult] (System.Func1[TResult] operation, System.Threading.CancellationToken cancellationToken) [0x00108] in :0 at Dotmim.Sync.BaseOrchestrator.OpenConnectionAsync (System.Data.Common.DbConnection connection, System.Threading.CancellationToken cancellationToken) [0x0017b] in

:0 at Dotmim.Sync.RemoteOrchestrator.EnsureSchemaAsync (System.Threading.CancellationToken cancellationToken, System.IProgress1[T] progress) [0x0012d] in :0 --- End of inner exception stack trace --- at Dotmim.Sync.BaseOrchestrator.RaiseError (System.Exception exception) [0x00046] in :0 at Dotmim.Sync.RemoteOrchestrator.EnsureSchemaAsync (System.Threading.CancellationToken cancellationToken, System.IProgress1[T] progress) [0x00f0a] in :0 at Dotmim.Sync.SyncAgent.SynchronizeAsync (Dotmim.Sync.Enumerations.SyncType syncType, System.Threading.CancellationToken cancellationToken, System.IProgress1[T] progress) [0x00d28] in :0 at mysqlconnectorxamarintest.MainPage.SyncDB () [0x000af] in /Users/Tibor/Projects/mysqlconnectorxamarintest/mysqlconnectorxamarintest/MainPage.xaml.cs:63 at mysqlconnectorxamarintest.MainPage.OnAppearing () [0x000d1] in /Users/Tibor/Projects/mysqlconnectorxamarintest/mysqlconnectorxamarintest/MainPage.xaml.cs:44 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 13.16.0.13/src/Xamarin.iOS/Foundation/NSAction.cs:178 at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 13.16.0.13/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at mysqlconnectorxamarintest.iOS.Application.Main (System.String[] args) [0x00001] in /Users/Tibor/Projects/mysqlconnectorxamarintest/mysqlconnectorxamarintest.iOS/Main.cs:17 — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub , or unsubscribe .
TybbyAce commented 4 years ago

Yes, the Mysql part can create the T1 table with no problem.

 using (MySqlConnection conn = new MySqlConnection(serverConnectionString))
            {
                try
                {
                    conn.Open();
                    string sql = "DROP TABLE IF EXISTS `itemsDB`.`T1`  ; CREATE TABLE  `itemsDB`.`T1` (`Id` int NOT NULL AUTO_INCREMENT, `Name` VARCHAR(50) NOT NULL, PRIMARY KEY(`Id`)  ); INSERT INTO `itemsDB`.`T1` (`Name`) VALUES('Abracadabra')";
                    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    cmd.ExecuteNonQuery();
                    Console.WriteLine("T1 table created, record added");
                    conn.Close();

                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.Message);

                }
            }

The crash happens here :

SyncAgent agent = new SyncAgent(clientProvider, serverProvider, tables);

Thanks

Mimetis commented 4 years ago

I'm sorry, regarding the stack trace, it seems you can not open a mysql connection.

To be able to debug correctly, you should clone the DMS repository, remove the references to the DMS packages, and make a reference directly to the project; That way you will have more information about the error raised from MySqlConnector

and make a test with async method, like OpenAsync() instead of Open() when you open a mysql connection That's the only difference i see

TybbyAce commented 4 years ago

Thank you, you were right. The problem was the async connection to Mysql (OpenAsync) , because Mysqlconnector does not work with Xamarin for some reason (maybe because the console app uses NetCore.App but Xamarin uses NetCore.Platforms, but this is beyond my capacity to judge). Anyways, as you advised, I downloaded DMS, it turns out your code is perfect, the problem lies with Mysqlconnector. So, I knocked it out, replaced it with stock MySql.Data and everything worked like charm (except for "case MySqlDbType.Bool" in MySqlDbMetadata.cs #337). I don't know why you picked Mysqlconnector over MySql.Data but you may want to reconsider your decision to be able to run your solution on Xamarin. Another thing I found is that your SQL query crashed on MySql 5.7 and MariDB 10.1 but was perfect on 8.02. (If you want me, I can open another issue for that for others).

Thanks again for the quick answers and for taking good care of your users. You're awesome!