using DuckDB, DBInterface
db = DBInterface.connect(DuckDB.DB,"C:\\Temp\\test.duckdb")
t = DBInterface.execute(db, "SELECT 1")
DBInterface.close!(db)
db = DBInterface.connect(DuckDB.DB,"C:\\Temp\\test.duckdb")
t = DBInterface.execute(db, "SELECT 1")
DBInterface.close!(db)
This is how I create and close connections, never had issues (except sometimes within Pluto, but I think that is separate).
ERROR: IO Error: Cannot open file "C:\Temp\test.duckdb": The process cannot access the file because it is being used by another process.
Stacktrace:
[1] DuckDB.DuckDBHandle(f::String, config::DuckDB.Config)
@ DuckDB C:\Users\kobus\.julia\packages\DuckDB\VdbjW\src\database.jl:17
[2] DuckDB.DB(f::String, config::DuckDB.Config)
@ DuckDB C:\Users\kobus\.julia\packages\DuckDB\VdbjW\src\database.jl:82
[3] DB
@ C:\Users\kobus\.julia\packages\DuckDB\VdbjW\src\database.jl:90 [inlined]
[4] connect(#unused#::Type{DuckDB.DB}, f::String)
@ DuckDB C:\Users\kobus\.julia\packages\DuckDB\VdbjW\src\database.jl:105
[5] top-level scope
@ c:\Source\Repos\RDAIngest.jl\src\close_test.jl:7
System: Windows 11
Latest version of Visual Studio Code
Julia v1.9.1
I have done some further tests and I get the same error if I run it under Windows Server 2019 and Windows 10. Same Julia 1.9.1. In these cases I also used a different user account to my original test.
I also ran the test in a Julia environment with just DBInterface and DuckDB installed. Same problem.
Any thoughts on where I could look next?
I would very much like to consider DuckDB for a project I have, but not being able to reliably close and open the database is a problem.
The DBeaver application has no problem with opening and closing DuckDb databases, including DuckDb databases created via julia. I have not worked with the DuckDb CLI. I have tried various file locations - it makes no difference.
I have noticed that when I close the DuckDb database in julia the temporary *.wal file that gets created when a database is opened, is not deleted on database closure, whereas when a database opened and closed with an application like DBeaver, the *wal file is removed.
I can successfully open the dummy database test.duckdb created by the julia code and upon closing the connection in DBeaver, the *.wal file is removed.
If I try to open the database using DBeaver, whilst the julia process is still active (after executing the first set of database open and close statements), I get the same error in DBeaver:
Reason:
IO Error: Cannot open file "d:\temp\test.duckdb": The process cannot access the file because it is being used by another process.
Hmmm ok, amending my first reply, I do get the bug. But it seems like mine happens one step after yours?
If I just simply take this and paste it into the REPL one time, no issues.
using DuckDB, DBInterface
db = DBInterface.connect(DuckDB.DB,"C:\\Temp\\test.duckdb")
t = DBInterface.execute(db, "SELECT 1")
DBInterface.close!(db)
db = DBInterface.connect(DuckDB.DB,"C:\\Temp\\test.duckdb")
t = DBInterface.execute(db, "SELECT 1")
DBInterface.close!(db)
If I try to run it as a script – errors.
If I paste it twice in the same REPL session – errors.
I was going to say that you should open an issue but I see you already have.
What use case do you need to repeatedly open and close the db in the same session?
I have a package that imports different datasets from different sources into the database (production system actually uses Sqlite). The function to import a specific data source open the database and close the database on import completion. The different functions a called from a main script one after another.