{"record":{"id":"a4b0a8308df7a7e1","repo":"litedb-org/LiteDB","slug":"connectionstring","errorCode":null,"errorMessage":"connectionString","messagePattern":"connectionString","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"LiteDB/Client/Database/LiteDatabase.cs","lineNumber":46,"sourceCode":"\n        #endregion\n\n        #region Ctor\n\n        /// <summary>\n        /// Starts LiteDB database using a connection string for file system database\n        /// </summary>\n        public LiteDatabase(string connectionString, BsonMapper mapper = null)\n            : this(new ConnectionString(connectionString), mapper)\n        {\n        }\n\n        /// <summary>\n        /// Starts LiteDB database using a connection string for file system database\n        /// </summary>\n        public LiteDatabase(ConnectionString connectionString, BsonMapper mapper = null)\n        {\n            if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));\n\n            _engine = connectionString.CreateEngine();\n            _mapper = mapper ?? BsonMapper.Global;\n            _disposeOnClose = true;\n        }\n\n        /// <summary>\n        /// Starts LiteDB database using a generic Stream implementation (mostly MemoryStream).\n        /// </summary>\n        /// <param name=\"stream\">DataStream reference </param>\n        /// <param name=\"mapper\">BsonMapper mapper reference</param>\n        /// <param name=\"logStream\">LogStream reference </param>\n        public LiteDatabase(Stream stream, BsonMapper mapper = null, Stream logStream = null)\n        {\n            var settings = new EngineSettings\n            {\n                DataStream = stream ?? throw new ArgumentNullException(nameof(stream)),\n                LogStream = logStream","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Client/Database/LiteDatabase.cs#L28-L64","documentation":"ArgumentNullException thrown by the LiteDatabase(ConnectionString, BsonMapper) constructor when connectionString is null. The constructor immediately delegates to connectionString.CreateEngine(), so a null connection string cannot build an engine and is rejected before any I/O.","triggerScenarios":"Constructing new LiteDatabase((ConnectionString)null) or new LiteDatabase((string)null) (the string overload forwards to this one); a configuration system returning null for the connection string; a dependency-injection registration missing the connection string value.","commonSituations":"Missing/empty 'ConnectionStrings' app setting; environment variable not set in the deployment; test helper passing null; typo in the config key name.","solutions":["Provide a valid connection string, e.g. new LiteDatabase(new ConnectionString(\"MyData.db\")).","Load the value from configuration and fail fast with a clear message if it is missing.","Validate the connection string is non-null before constructing LiteDatabase."],"exampleFix":"// before\nvar db = new LiteDatabase((ConnectionString)null);\n\n// after\nvar cs = Configuration.GetConnectionString(\"LiteDB\")\n    ?? throw new InvalidOperationException(\"LiteDB connection string is not configured.\");\nvar db = new LiteDatabase(new ConnectionString(cs));","handlingStrategy":"validation","validationCode":"var cs = Configuration.GetConnectionString(\"LiteDB\")\n    ?? throw new InvalidOperationException(\"LiteDB connection string is missing in configuration.\");\nvar db = new LiteDatabase(new ConnectionString(cs));","typeGuard":"static bool IsValidConnectionString(string s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":null,"preventionTips":["Centralize connection-string loading in one config helper that throws on missing values.","Fail fast at startup with a clear message if the connection string is absent.","Add a startup health check that opens the database."],"tags":["constructor","connection-string","argumentnull","configuration"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}