Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLCE Connections: Keep them open or let them close?

Keeping performance on a mobile device in mind, what do you think is the best approach with an SQLCE Connection. Keep it open for the duration of the application or let it close whenever a call to the database is needed.

Obviously this depends a little on the nature of your application however I'm curious to hear what the group has implemented and why.

like image 676
Mat Nadrofsky Avatar asked Dec 22 '08 13:12

Mat Nadrofsky


People also ask

Why is it good practice to disconnect your database connection when you're finished with it?

It's a good idea to close the connection when you're done using it to ensure that your changes actually go to the store. A power loss after a write and before a flush will lose data.

Which syntax should be used for a SQL Server Compact connection string?

The file path and name of the SQL Server Compact database. To indicate a relative path to the database from the application directory, use the Data Source = |DataDirectory| (enclosed in pipe symbols) substitution string.


2 Answers

You should definitely watch Steve Lasker's PDC08 session about SQL Server Compact Edition. There's a part about performance, best practices and his own benchmarks (~37:00).

In short, keep it open, try to reuse commands, and use SqlCeResultSet for bulk operations.

like image 165
Martin Plante Avatar answered Sep 28 '22 05:09

Martin Plante


For my device, I kept it open during the lifetime of the application. If the functionality of the application depends on the SQLCE connection throughout, this makes sense.

like image 43
Dave Markle Avatar answered Sep 28 '22 04:09

Dave Markle