Information about Windows Iot Sql Lite

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Information about Windows Iot Sql Lite

Magni, Andrea - IT CONSULTANT

Good Afternoon,
following this example
 
[ http://blog.chrisbriggsy.com/Using-SQLITE-in-Windows-10-IoT-Core-Insider-Preview/ ]( http://blog.chrisbriggsy.com/Using-SQLITE-in-Windows-10-IoT-Core-Insider-Preview/ )
 
Im trying to use Sql and Linq with c# and windows iot.
 
I'm not able to understand why randomly a program came out with "Access Violation".
 
Below reported the code that i'm using ...
 
DATABASE CONNECTION:[code]  public  void ConnectToDatabase()        {           // await Task.Delay(TimeSpan.FromSeconds(0));           // await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>           // {                                                 path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");            //path = Path.Combine("C:\\DB", "db.sqlite");            //using (var conn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))            //{            //    conn.CreateTable<Contabilita>();            //    conn.RunInTransaction(() =>            //    {            //        conn.Insert(new Contabilita()            //        {            //            NumberOfCredit = 1,            //            NumberOfMatches = 2,            //            NumberOfTotalCoin = 3,            //            NumberOfWinMatches = 1,            //            Antimanomission = 0            //        });            //    });            //}            conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);                //conn.DeleteAll<Contabilita>();                //conn.CreateTable<Contabilita>();                //conn.Insert(new Contabilita()                //{                //    NumberOfCredit = 1,                //    NumberOfMatches = 0,                //    NumberOfTotalCoin = 0,                //    NumberOfWinMatches = 0                //});                conn.Commit();                //stopWatch1.Start();                //conn.BeginTransaction();                //Contabilita Test = new Contabilita();                //Test.Id = 1;                //Test.NumberOfCredit = 0;                //Test.NumberOfMatches = 345;                //Test.NumberOfTotalCoin = 1000;                //Test.NumberOfWinMatches = 236;                //Test.Antimanomission = 0;                //conn.Update(Test);                //conn.Commit();                //stopWatch1.Stop();                //System.Diagnostics.Debug.WriteLine("Per Aggiornare il Db servono: " + Convert.ToString(ts1.Seconds) + " Secondi e " + Convert.ToString(ts1.Milliseconds) + " Millisecondi");                //ts1 = stopWatch1.Elapsed;                //stopWatch1.Reset();           // });        }[/code]DATA BASE UPDATE:[code]       public async void UpdateContabilita(float NumeroCrediti, float NumeroPartite, float NumerodiMonete, float NumeroPartiteVinte,float Antimanomissione)        {            //await Task.Delay(TimeSpan.FromSeconds(0));            //conn.BeginTransaction();            //Contabilita Test = new Contabilita();            //Test.Id = 1;            //Test.NumberOfCredit = NumeroCrediti;            //Test.NumberOfMatches = NumeroPartite;            //Test.NumberOfTotalCoin = NumerodiMonete;            //Test.NumberOfWinMatches = NumeroPartiteVinte;            //Test.Antimanomission = Antimanomissione;            //conn.Update(Test);            //conn.Commit();            try            {                await Task.Delay(TimeSpan.FromSeconds(0));                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>                {                    conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path);                    conn.BeginTransaction();                    Contabilita Test = new Contabilita();                    Test.Id = 1;                    Test.NumberOfCredit = NumeroCrediti;                    Test.NumberOfMatches = NumeroPartite;                    Test.NumberOfTotalCoin = NumerodiMonete;                    Test.NumberOfWinMatches = NumeroPartiteVinte;                    Test.Antimanomission = Antimanomissione;                    conn.Update(Test);                    conn.Commit();                    // ConnectToDatabase();                    //conn.BeginTransaction();                    //var tmp = conn.Table<Contabilita>().FirstOrDefault(c => c.Id == 1);                    ////var tmp = conn.Table<Contabilita>().FirstOrDefault();                    //tmp.NumberOfCredit = NumeroCrediti;                    //tmp.NumberOfMatches = NumeroPartite;                    //tmp.NumberOfTotalCoin = NumerodiMonete;                    //tmp.NumberOfWinMatches = NumeroPartiteVinte;                    //tmp.Antimanomission = Antimanomissione;                    //conn.Update(tmp);                    //conn.Commit();                     conn.Close();                });            }            catch (IOException e)            {                // Extract some information from this exception, and then                   // throw it to the parent method.                  System.Diagnostics.Debug.WriteLine("{0} Exception caught.", e);            }        }[/code]Database Read:[code]public  void ReadContabilita()        {            try            {              //  await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High,  () =>                //{                    int id;                    var tmp = conn.Table<Contabilita>().FirstOrDefault();                    id = tmp.Id;                    //NumeroCrediti = tmp.NumberOfCredit;                    //NumeroPartite = tmp.NumberOfMatches;                    //NumerodiMonete = tmp.NumberOfTotalCoin;                    //NumeroPartiteVinte = tmp.NumberOfWinMatches;                    //Antimanomissione = tmp.Antimanomission;                    Gioco[Counter, NumberOfCredit] = tmp.NumberOfCredit;                    Gioco[Counter, NumberOfMatches] = tmp.NumberOfMatches;                    Gioco[Counter, NumberOfTotalCoin] = tmp.NumberOfTotalCoin;                    Gioco[Counter, NumberOfWinMatches] = tmp.NumberOfWinMatches;                    Gioco[Counter, Antimanomission] = tmp.Antimanomission;                    System.Diagnostics.Debug.WriteLine("Id: " + tmp.Id.ToString());                    System.Diagnostics.Debug.WriteLine("Number of Credit: " + tmp.NumberOfCredit.ToString());                    System.Diagnostics.Debug.WriteLine("Number of Macthes: " + tmp.NumberOfMatches.ToString());                    System.Diagnostics.Debug.WriteLine("Number of TotalCoin: " + tmp.NumberOfTotalCoin.ToString());                    System.Diagnostics.Debug.WriteLine("Number of WinMatches: " + tmp.NumberOfWinMatches.ToString());                    System.Diagnostics.Debug.WriteLine("Antimanomission: " + tmp.Antimanomission.ToString());                // });                conn.Close();            }            catch (Exception e)            {                System.Diagnostics.Debug.WriteLine("{0} Exception caught.", e);            }        }[/code]
 
I've tested the code also on normal desktop app but didn't give a issues ...
 
Also I'm not able to catch the exception related to the db ... for sure is coming from Sql lite because when i remove from the project is working without any problem.
 
Could you kindly help me ?
 
Thanks in advanced,
Andrea
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users