Click here to Skip to main content
15,506,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application that runs on several machines simultaneously, all on the same local network. The data access code in the application is constructed so that every occurrence of SQLiteConnection.Open() is paired with an SQLiteConnection.Close(), and the time-gap between these is minimal.

I was doing maintenance on the installation last weekend. No one was in the office and therefore no one was using the system. It is possible someone left the application open on their machine and simply logged out of Windows or maybe simply put Windows into sleep mode.

I found I could not rename the shared database file. I'm puzzled by this. Why should SQLite keep the file locked at the file-level when - in theory at least - there are no currently open connections?

What I have tried:

I tried restarting the machine I was on, just to be sure I was not the one locking the file somehow, but it was not possible to restart all the other machines on the network.
Updated 12-Apr-21 23:28pm

1 solution

Probably connection pooling:
SQL Server Connection Pooling - ADO.NET | Microsoft Docs[^]

NB: Rather than pairing each Open with a Close, you should be wrapping the connection objects in a using block. That way, they will be cleaned up even if the code throws an exception.
Share this answer
Patrick Skelton 13-Apr-21 4:36am    
That does sound like a candidate. However, it does say 'The connection pooler removes a connection from the pool after it has been idle for approximately 4-8 minutes'. I do find it odd that any should be open on a weekend.

Point taken about the using statement though. I'd feel happier if I refactored the code to use that approach.

Thanks for the information, Richard.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900