Jay Bowman
Jay Bowman

Reputation: 69

When using sqlite-net-pcl with Xamarin.Forms what are best practices for create connection

I'm using SQLite-Net-Pcl in Xamarin.Forms application, I have created a singleton dataStore class for all my database methods. What is the best practice for creating a SQLiteConnection? Should there be a private readonly connection object on your class and use it in all your db operations. Or should you use create a new SQLiteConnection in every method? Also should I use a lock() statement around my db code?

lock(lockerObj)
{ 
  // db code 
}

Upvotes: 0

Views: 318

Answers (1)

webwires
webwires

Reputation: 1907

That depends a lot on the nature of your data and the nature / complexity of your application.

For us we have had no issues using a single connection and using the lock statement to help ensure serialized updates to the database. That is the simplest to implement and manage since you don't need to be concerned with connection isolation.

But that is not a one size fits all solution.

Upvotes: 1

Related Questions