Skip to content

Error is "unable to open database file: out of memory (14)" when parent directory does not exist

Here's a reproduction:

package main

import (
	"database/sql"

	_ "modernc.org/sqlite"
)

func main() {
	db, err := sql.Open("sqlite", "file:nonexist/ent.db")
	if err != nil {
		panic(err)
	}
	if err := db.Ping(); err != nil {
		panic(err)
	}
}

The Ping() call returns an error with the string: unable to open database file: out of memory (14)

Why is it "out of memory" instead of the file not existing? Specifically, the file must be in a directory that does not exist.

Edited by Liam Bowen