4

I am trying to run a very simple C# code to read data from SQLite. I am using Xamarin as my IDE and on a Mac. I can compile the code.. but i get this error when i try to connect to the SQLite Database. Any ideas what I am missing.

I have included SQLite and SQLite.Data using Nuget. I get a clean build the error is at runtime. I have added the code to the end of the error

SQLite.Interop.dll at (wrapper managed-to-native) 

System.Data.SQLite.UnsafeNativeMethods:sqlite3_config_none     (System.Data.SQLite.SQLiteConfigOpsEnum)
      at System.Data.SQLite.SQLite3.StaticIsInitialized () <0x5934cd8 + 0x0007b> in <filename unknown>:0 
      at System.Data.SQLite.SQLiteLog.Initialize () <0x5934998 + 0x0001b> in <filename unknown>:0 
      at System.Data.SQLite.SQLiteConnection..ctor (System.String connectionString, Boolean parseViaFramework) <0x5932758 + 0x0003b> in <filename unknown>:0 
      at System.Data.SQLite.SQLiteConnection..ctor (System.String connectionString) <0x5932728 + 0x0001f> in <filename unknown>:0 
      at (wrapper remoting-invoke-with-check) System.Data.SQLite.SQLiteConnection:.ctor (string)



using System;
using System.Configuration;
using System.Linq;
using System.Data;
using System.Text;

using System.Data.SQLite;

using utils;

public class DataManager
{
    public static string GetData(string sql)
    {
        string JsonString = "{}";
        SQLiteConnection sqlLiteConnection = null;
        try
        {
            sqlLiteConnection = new SQLiteConnection(ConfigurationManager.ConnectionStrings["APP_DB"].ConnectionString);
            sqlLiteConnection.Open();

            SQLiteDataAdapter sqlDA = new SQLiteDataAdapter(sql, sqlLiteConnection);
            DataTable table = new DataTable();
            Logger.Log(sql);
            sqlDA.Fill(table);
            sqlDA.Dispose();

        }
        catch (Exception ex)
        {
            Logger.Log(ex.Message);
            Logger.Log(ex.StackTrace);
        }
        finally
        {
            if (sqlLiteConnection != null && sqlLiteConnection.State == System.Data.ConnectionState.Open)
                sqlLiteConnection.Close();
        }
        return JsonString;
    }
}
shivas
  • 913
  • 10
  • 15

0 Answers0