尝试通过C#

时间:2018-10-12 00:53:38

标签: c# mysql xamarin

我正在使用lib MySql.Data尝试连接并在表中插入一些数据,但是

我的代码:

using System;
using System.Data;
using MySql.Data.MySqlClient;

public class DBCon
{
    public static class Banco
    {
        public static async void Executar(string query)
        {
            var connection = new MySqlConnection("Server=XXXXXXX;Database=YYYYYYYYY;Uid=ZZZZZZZ;Pwd=PPPPPPPPP");
            var command = connection.CreateCommand();

            try
            {
                connection.Open();
                command.CommandText = query;
                command.ExecuteNonQuery();
            }
            catch(Exception)
            {
                throw;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                    connection.Close();
            }
        }
    }
}

执行查询:

DBCon.Banco.Executar("INSERT INTO table (device,latitude,longitude) VALUES ('abc123','"+position.Latitude+"','"+position.Longitude+"')");

在调试时获取这些行:

10-12 00:41:32.931 E/mono    (12296): 
10-12 00:41:32.931 E/mono    (12296): Unhandled Exception:
10-12 00:41:32.931 E/mono    (12296): 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.PlatformNotSupportedException: Operation is not supported on this platform. 
10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ClientConfigPaths..ctor (System.String exePath, System.Boolean includeUserConfig) [0x00050] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ClientConfigPaths.GetPaths (System.String exePath, System.Boolean includeUserConfig) [0x00018] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ClientConfigurationHost.get_ConfigPaths () [0x0000a] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ClientConfigurationHost.GetStreamName (System.String configPath) [0x0006d] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp () [0x00000] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp () [0x00006] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ClientConfigurationSystem..ctor () [0x00051] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem () [0x00024] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):    --- End of inner exception stack trace --- 10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem () [0x00060] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ConfigurationManager.PrepareConfigSystem () [0x0000a] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x0000a] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.931 E/mono    (12296):   at MySql.Data.MySqlClient.MySqlConfiguration..cctor () [0x00000] in <8d19be5077ed43c6a3a11313ef774535>:0  10-12 00:41:32.931 E/mono    (12296):    --- End of inner exception stack trace --- 10-12 00:41:32.931 E/mono    (12296):   at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor () [0x0001e] in <8d19be5077ed43c6a3a11313ef774535>:0  10-12 00:41:32.931 E/mono    (12296):    --- End of inner exception stack trace --- 10-12 00:41:32.931 E/mono    (12296):   at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in <8d19be5077ed43c6a3a11313ef774535>:0  10-12 00:41:32.931 E/mono    (12296):   at DBCon+Banco+<Executar>d__0.MoveNext () [0x00059] in D:\apps\BatePapo\BatePapo\BatePapo\DBCon.cs:22  10-12 00:41:32.931 E/mono    (12296): --- End of stack trace from previous location where exception was thrown --- 10-12 00:41:32.931 E/mono    (12296):   at (wrapper dynamic-method) System.Object.47(intptr,intptr) 10-12 00:41:32.932 E/mono-rt (12296): [ERROR] FATAL UNHANDLED 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.PlatformNotSupportedException: Operation is not supported on this platform. 10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ClientConfigPaths..ctor (System.String exePath, System.Boolean includeUserConfig) [0x00050] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ClientConfigPaths.GetPaths (System.String exePath, System.Boolean includeUserConfig) [0x00018] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ClientConfigurationHost.get_ConfigPaths () [0x0000a] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ClientConfigurationHost.GetStreamName (System.String configPath) [0x0006d] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp () [0x00000] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp () [0x00006] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ClientConfigurationSystem..ctor () [0x00051] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem () [0x00024] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):    --- End of inner exception stack trace --- 10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ConfigurationManager.EnsureConfigurationSystem () [0x00060] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ConfigurationManager.PrepareConfigSystem () [0x0000a] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x0000a] in <0e721f564ffa49e6b1d97ad7b9fda1f2>:0  10-12 00:41:32.932 E/mono-rt (12296):   at MySql.Data.MySqlClient.MySqlConfiguration..cctor () [0x00000] in <8d19be5077ed43c6a3a11313ef774535>:0  10-12 00:41:32.932 E/mono-rt (12296):    --- End of inner exception stack trace --- 10-12 00:41:32.932 E/mono-rt (12296):   at MySql.Data.MySqlClient.Replication.ReplicationManager..cctor () [0x0001e] in <8d19be5077ed43c6a3a11313ef774535>:0  10-12 00:41:32.932 E/mono-rt (12296):    --- End of inner exception stack trace --- 10-12 00:41:32.932 E/mono-rt (12296):   at MySql.Data.MySqlClient.MySqlConnection.Open () [0x0016d] in <8d19be5077ed43c6a3a11313ef774535>:0  10-12 00:41:32.932 E/mono-rt (12296):   at DBCon+Banco+<Executar>d__0.MoveNext () [0x00059] in D:\apps\BatePapo\BatePapo\BatePapo\DBCon.cs:22  10-12 00:41:32.932 E/mono-rt (12296): --- End of stack trace from previous location where exception was thrown --- 10-12 00:41:32.932 E/mono-rt (12296):   at (wrapper dynamic-method) System.Object.47(intptr,intptr) 10-12 00:41:32.935 D/        (12296): HostConnection::get() New Host Connection established 0xd02c5500, tid 12296

任何人都可以看到错误吗?

0 个答案:

没有答案