{"record":{"id":"368a3861892b8561","repo":"googleapis/mcp-toolbox","slug":"unable-to-create-db-connection-w-368a38","errorCode":null,"errorMessage":"unable to create db connection: %w","messagePattern":"unable to create db connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/sqlite/sqlite.go","lineNumber":64,"sourceCode":"\t}\n\treturn actual, nil\n}\n\ntype Config struct {\n\tName         string `yaml:\"name\" validate:\"required\"`\n\tType         string `yaml:\"type\" validate:\"required\"`\n\tDatabase     string `yaml:\"database\" validate:\"required\"` // Path to SQLite database file\n\tSQLCommenter *bool  `yaml:\"sqlCommenter\"`\n}\n\nfunc (r Config) SourceConfigType() string {\n\treturn SourceType\n}\n\nfunc (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {\n\tdb, err := initSQLiteConnection(ctx, tracer, r.Name, r.Database)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to create db connection: %w\", err)\n\t}\n\n\terr = db.PingContext(context.Background())\n\tif err != nil {\n\t\tdb.Close()\n\t\treturn nil, fmt.Errorf(\"unable to connect successfully: %w\", err)\n\t}\n\n\ts := &Source{\n\t\tConfig: r,\n\t\tDb:     db,\n\t}\n\treturn s, nil\n}\n\nvar _ sources.Source = &Source{}\n\ntype Source struct {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/sqlite/sqlite.go#L46-L82","documentation":"sqlite Config.Initialize (internal/sources/sqlite/sqlite.go:64) opens the SQLite database via initSQLiteConnection (sql.Open over the sqlite driver). If the driver fails to open the database file (or a prep-hook/pragma fails), the error is wrapped as \"unable to create db connection\". Note sql.Open usually doesn't touch the file, so this most often indicates a bad DSN/path configuration or driver-level error.","triggerScenarios":"Initialize called with a sqlite source whose name/database path is invalid: empty database path, directory doesn't exist, or the driver's Open hook (e.g. PRAGMA setup) fails.","commonSituations":"Typo in the database file path; parent directory not created before connecting; read-only filesystem; using `file:...` URI syntax incorrectly; missing CGO or driver not compiled in for some sqlite drivers.","solutions":["Verify the `database` path in the source config points to a writable location and its parent directory exists","Create the directory before starting: mkdir -p $(dirname /path/to/db.sqlite3)","Check filesystem permissions on the db file and directory","If using a URI DSN, validate the `file:...?...` syntax the driver expects"],"exampleFix":"// before\nname: my-sqlite\ndatabase: /nonexistent/dir/data.db\n// after\nname: my-sqlite\ndatabase: /tmp/toolbox/data.db  # mkdir -p /tmp/toolbox first","handlingStrategy":"validation","validationCode":"if dbPath == \"\" { return errors.New(\"sqlite database path is empty\") }\nif err := os.MkdirAll(filepath.Dir(dbPath), 0o755); err != nil {\n\treturn fmt.Errorf(\"cannot create db directory: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create the parent directory before pointing sqlite at a new file","Use absolute paths in source configs","Confirm the container/host filesystem is writable"],"tags":["sqlite","connection","config"],"backgroundTag":"database-connection-open-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}