{"record":{"id":"ef6796d1abed60fe","repo":"litedb-org/LiteDB","slug":"database-not-connected-ef6796","errorCode":null,"errorMessage":"Database not connected","messagePattern":"Database not connected","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LiteDB.Shell/Commands/ShowCollections.cs","lineNumber":20,"sourceCode":"using System.Linq;\n\nnamespace LiteDB.Shell.Commands\n{\n    [Help(\n        Name = \"show collections\",\n        Syntax = \"show collections\",\n        Description = \"List all collections inside datafile.\"\n    )]\n    internal class ShowCollections : IShellCommand\n    {\n        public bool IsCommand(StringScanner s)\n        {\n            return s.Match(@\"show\\scollections$\");\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 cols = env.Database.GetCollectionNames().OrderBy(x => x).ToArray();\n\n            if (cols.Length > 0)\n            {\n                env.Display.WriteLine(ConsoleColor.Cyan, string.Join(Environment.NewLine, cols));\n            }\n        }\n    }\n}","sourceCodeStart":2,"sourceCodeEnd":30,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB.Shell/Commands/ShowCollections.cs#L2-L30","documentation":"Thrown by the LiteDB shell 'show collections' command when no database is open. Listing collections requires querying an open LiteDatabase, so env.Database must be non-null; issuing the command before connecting triggers this guard.","triggerScenarios":"Typing 'show collections' in the LiteDB shell before issuing an 'open'/'connect' command, so env.Database is still null.","commonSituations":"New shell session with no auto-connect; a failed connect left the database null; running the command against a stream-based or disconnected shell state.","solutions":["Open a database first with 'open <filename>' before 'show collections'.","Confirm the connect step reported success; if it errored, fix the connection string/path and retry.","Start the shell with the database path as an argument to auto-connect."],"exampleFix":"// before\n> show collections\n// after\n> open MyData.db\n> show collections","handlingStrategy":"validation","validationCode":"if (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":["Connect before issuing data commands in the shell.","Verify the open command succeeded before listing collections.","Auto-connect by passing the database path at shell startup."],"tags":["shell","connection","collections"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}