{"record":{"id":"7de3c45abbd731e2","repo":"dotnet/orleans","slug":"value-cannot-be-null-parameter-connectionstring","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'connectionString')","messagePattern":"Value cannot be null\\. \\(Parameter 'connectionString'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/AdoNet/Shared/Storage/DbConnectionFactory.cs","lineNumber":112,"sourceCode":"            {\n                if (exceptions == null)\n                {\n                    exceptions = new List<Exception>();\n                }\n                exceptions.Add(ex);\n            }\n        }\n\n        public static DbConnection CreateConnection(string invariantName, string connectionString)\n        {\n            if (string.IsNullOrWhiteSpace(invariantName))\n            {\n                throw new ArgumentNullException(nameof(invariantName));\n            }\n\n            if (string.IsNullOrWhiteSpace(connectionString))\n            {\n                throw new ArgumentNullException(nameof(connectionString));\n            }\n\n            var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;\n            var connection = factory.CreateConnection();\n\n            if (connection == null)\n            {\n                throw new InvalidOperationException($\"Database provider factory: '{invariantName}' did not return a connection object.\");\n            }\n\n            connection.ConnectionString = connectionString;\n            return connection;\n        }\n\n        public static void ValidateDataSource(string invariantName, DbDataSource dataSource)\n        {\n            ArgumentNullException.ThrowIfNull(dataSource);\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/src/AdoNet/Shared/Storage/DbConnectionFactory.cs#L94-L130","documentation":"Thrown by DbConnectionFactory.CreateConnection when the connectionString argument is null, empty, or whitespace. A connection string is mandatory to open a database connection; Orleans rejects it early with an ArgumentNullException on the 'connectionString' parameter rather than letting the provider throw an opaque error.","triggerScenarios":"Calling DbConnectionFactory.CreateConnection(invariant, null), CreateConnection(invariant, \"\"), or CreateConnection(invariant, \"   \"). Occurs when AdoNetStreamOptions.ConnectionString is unset and no DataSource is configured, or when a connection string is read from a missing secrets/env source.","commonSituations":"Forgetting to bind the connection string from configuration; the environment variable holding it is not set in the deployed environment; a typo in the config key name; using DataSource-based config but accidentally calling CreateConnection with an empty string.","solutions":["Provide a valid, non-empty connection string matching the chosen invariant's provider.","Bind AdoNetStreamOptions.ConnectionString from a verified configuration source (e.g. IConfiguration.GetSection).","If using DbDataSource instead, do not pass a connection string to CreateConnection; configure DataSource and use the data-source path."],"exampleFix":"// before\noptions.ConnectionString = config[\"NotTheRightKey\"]; // null\nvar conn = DbConnectionFactory.CreateConnection(invariant, options.ConnectionString);\n\n// after\noptions.ConnectionString = config.GetConnectionString(\"OrleansStreamDb\");\nvar conn = DbConnectionFactory.CreateConnection(invariant, options.ConnectionString);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(connectionString))\n    throw new InvalidOperationException(\"A connection string (or DbDataSource) must be configured.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate that exactly one of ConnectionString or DataSource is set before building.","Use IConfiguration.GetConnectionString to bind from a verified source.","Surface missing connection strings in your own bootstrap with an actionable message."],"tags":["adonet","argument-null","configuration","database","connection-string","orleans"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}