GayatriGokhale-4983 avatar image
0 Votes"
GayatriGokhale-4983 asked GayatriGokhale-4983 commented

Xamarin Forms `SQLiteAsyncConnection` throws error when trying to add data with new columns in existing table

I am using SQLiteAsyncConnection to perform CRUD operation in my xamarin.forms app.

My problem is. I have existing table with data in it. My requirement changed and I needed to add few more columns into that table. because I have data in that table, I can't drop it but I want to update existing one with newly added columns. but It's failing and even it doesn't give proper error message.

please find below screenshot that summarizes my problem44423-screenshot-48.png

also I am not able to use using keyword to control scope of connection object.

Any help would be appreciated.


screenshot-48.png (117.5 KiB)
· 10
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@GayatriGokhale-4983 Hi, is the column added to the table successfully but it is not displayed? Or the addition operation is failed? To use database in Xamarin.Forms, you could refer to this tutorial: And you could check the official sample for a direction.

0 Votes 0 ·

Is it problem because I am using InsertWithChildrenAsync because I have foreign key constraint in my model.

because I run above sample and simple InsertAsync is working with new column added in TodoItem Model.

please find attachment of my model class

0 Votes 0 ·
screenshot-50.png (104.1 KiB)
screenshot-51.png (116.8 KiB)

Sorry for the late reply. The two tables have the relationship, make sure both the two table is available. Try the following code:

var db = Utils.CreateConnection();

var tblUnit = new TblUnit()
db.Insert(tblUnit);   // Insert the object in the database

var item = new Item()
db.Insert(item);   // Insert the object in the database
tblUnit.Items = new List<Item> { item };

0 Votes 0 ·
Show more comments

What is the exception you're seeing?

0 Votes 0 ·

@jcmanke I actually see null in the ex variable and by hovering on Exception It shows some other data but not related to errors.44733-screenshot-49.png

Am I missing something ?

0 Votes 0 ·
screenshot-49.png (123.4 KiB)
jcmanke avatar image jcmanke GayatriGokhale-4983 ·

Try adding Debug.WriteLine(ex) to your catch block and see what that outputs. Debugging exceptions thrown by async methods can be tricky.

0 Votes 0 ·
Show more comments

0 Answers