{"record":{"id":"0cfcf13dd9b78365","repo":"litedb-org/LiteDB","slug":"database-not-connected","errorCode":null,"errorMessage":"Database not connected","messagePattern":"Database not connected","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LiteDB.Shell/Commands/Run.cs","lineNumber":23,"sourceCode":"{\n    [Help(\n        Name = \"run\",\n        Syntax = \"run <filename>\",\n        Description = \"Queue shell commands inside filename to be run in order.\",\n        Examples = new string[] {\n            \"run scripts.txt\"\n        }\n    )]\n    internal class Run : IShellCommand\n    {\n        public bool IsCommand(StringScanner s)\n        {\n            return s.Scan(@\"run\\s+\").Length > 0;\n        }\n\n        public void Execute(StringScanner s, Env env)\n        {\n            if (env.Database == null) throw new Exception(\"Database not connected\");\n\n            var filename = s.Scan(@\".+\").Trim();\n\n            foreach (var line in File.ReadAllLines(filename))\n            {\n                env.Input.Queue.Enqueue(line);\n            }\n        }\n    }\n}","sourceCodeStart":5,"sourceCodeEnd":33,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB.Shell/Commands/Run.cs#L5-L33","documentation":"Thrown by the LiteDB shell 'run' command when no database is open. The Run command reads a script file and queues its lines for execution, but executing any queued SQL requires an active connection, so env.Database must be set first via an 'open' or 'connect' command.","triggerScenarios":"Typing 'run scripts.txt' in the LiteDB shell before opening a database with 'open <file>' (or equivalent connect command). The shell's env.Database is null until a connection command populates it.","commonSituations":"Starting a shell session and immediately running a script without connecting; the connection string from a prior 'open' failed silently so env.Database stayed null; scripting the shell in a non-interactive pipeline that omits the connect step.","solutions":["Run the connect/open command first, e.g. 'open MyData.db', then 'run scripts.txt'.","Verify the open command succeeded (no error written) before invoking run.","Pass the database file as a shell startup argument so the connection is established before commands are read."],"exampleFix":"// before\n> run scripts.txt\n// after\n> open MyData.db\n> run scripts.txt","handlingStrategy":"validation","validationCode":"// Guard the run command when scripting the shell\nif (env.Database == null)\n{\n    env.Display.WriteLine(ConsoleColor.Yellow, \"No database open. Run: open <file>\");\n    return;\n}","typeGuard":"static bool HasDatabase(Env env) => env?.Database != null;","tryCatchPattern":null,"preventionTips":["Always issue the connect/open command before run in shell scripts.","Start the shell with the database path argument to auto-connect.","Check command output for connect errors before proceeding."],"tags":["shell","connection","run-command"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}