EF 7 is not releasing the SQLite DB file after migrate - entity-framework

We recently migrated our EF from 2.0 to 7.0.1. After EF migration, we are facing a challange that sqlite db file not released after calling the DatabaseFacade.Migrate method (we are using the code first apporach). File is open at the EF side due to that unable to access like copy/delete the sqlite db file. Could someone help us on this issue ?
SQlite db has to be release after calling DatabaseFacade.Migrate

The SQLite provider pools connections, improving connection speed significantly but keeping connections open. You can disable pooling by adding Pooling=false to the connection string or calling SqliteConnection.ClearAllPools() at the point where you want them to be closed.

Related

EF Core with SQL Server persistence requires VIEW SERVER STATE permissions?

If I use EF Core against SQL Server, and the user account on the connection does not have permissions for VIEW SERVER STATE on object 'server', database 'master', the operation will fail with a DBUpdateException stating that this permission is missing.
What is EF Core trying to do that requires this permission? Is there any way for me to disable whatever it is doing that requires it? or do I have to add this permission?
Check if there is any access to the tables like sys.dm_tran_active_transactions, sys.dm_tran_current_transaction when you do the save changes in EF. Maybe it could be through a table trigger. I faced a similar issue due to a trigger trying to access those sys tables.

iOS Programming suggestion request REF sqlite/iOS app design

I currently have an iOS app that provides a sqlite DB for the data backend to the app. This data is basically a list of information. Within this app I allow the users to mark records as bookmarked (sets a value in the DB). The problem here is when I post updates to the app via the internet (update through software) for data changes, the new downloaded DB wipes out the old one thereby removing the user customizations.
Any ideas on an easy method to search the current sqlite DB for those changes, store them temporarily, then import the new DB and transfer the changes to the new DB? Could I for instance use a Core Data element at the same time as using the sqlite DB backend? Maybe a key/value pair system?
Any suggestions would be greatly appreciated.
Thanks
-LK
The way I've done it is this:
For your new version, rename your .sqlite file e.g. foo-v2.sqlite. Then, during initialization, check to see if the sqlite file for the old version is there - if so, copy over the necessary info and then delete the old sqlite file.

how to use sqlite db created from core data after repopulating it on the server side?

I created sqlite db from core data and i want to repopulate it on the server side and download it again to device with overwriting existing sqlite db. Is it possible to repopulate on server side and is it work if overwrite with existing db?
As far as i know, if you are saving data through core data, it will create usual sqlite db, but all tables, field names will has a Z_ prefix.
You can simply use this db on the server side, that download it as file and overwrite exiting db on device.
Sorry for my broken english if something wrong.
Do not ever mess with a Core Data db outside of the application. In fact, forget it is a db because it is simply a storage mechanism.
What you need to do is to send the objects to the server (xml is probably the easiest), manipulate the data on the server, send the data back to the app, import the data into Core Data.

sqlite3 database is getting locked

I am creating an application with sqlite. I am performing all kind of task on the database Insert, Update, Delete, Select.
For that I open the database every time, Then execute my query using sqlite3_step() and after the result I use sqlite3_finalize() and sqlite3_close() methods. It is working well in most cases. I am not getting when its happening but some times my database gets locked with the same process I follow and some time it works.
I need to unlock database so even in any case my database get locked then I can unlock it or Plz guide me if I can check by code that my database is locked so I can replace my database with the resource database.
I am using webservice too so I don't have issue about data loss.
Is it make sense if I replace my database if it get locked or if there is any way to unlock the database.
Open database once in the beginning. And close it in the end in AppWillterminate function. You are only consuming time by opening and closing it in every database function.
As far as database lock is concerned, it gets locked when some application is still using it and other application is trying to get its access.
This could be your app, or possibly the sqlite manager add-on of your firefox.
I faced same problem once and what i did was
Disabled the option in sqlite add-on where it remembers the previously opened database.
Restart xcode, simulator.
Make a copy of the sqlite file (desktop), delete it from the project and then add in project again from desktop.
The last solution sounds weird, but i was mad that time.
I hope this could help you.

When to open and close the connection while using sqlite with singleton pattern

I am developing an application for IPhone and using sqlite to connect to db. I am trying to use the singleton pattern for connecting to the db and retrieving the data.
I would like to know which is the best way to maintain the connection, should I keep the connection open till the application is closed or should I open and close the connection for every call that I make ?
SQLite must re-parse the database schema each time a new connection is made. This can be time consuming. Leaving the connection open also provides opportunities for SQLite to cache data. Since you get ACID transactions even without closing the connection, there is little reason to close it. So, keep the SQLite connection open until the application is closed.