dotnet/orleans · error · ArgumentException

Connection string must contain characters

Error message

Connection string must contain characters

What it means

Thrown by RelationalStorage.CreateInstance(string invariantName, string connectionString) when connectionString is null, empty, or whitespace. The connection string is required to open connections via DbConnectionFactory; a blank value cannot reach any database. ArgumentException names 'connectionString'.

Source

Thrown at src/AdoNet/Shared/Storage/RelationalStorage.cs:103

        }


        /// <summary>
        /// Creates an instance of a database of type <see cref="IRelationalStorage"/>.
        /// </summary>
        /// <param name="invariantName">The invariant name of the connector for this database.</param>
        /// <param name="connectionString">The connection string this database should use for database operations.</param>
        /// <returns></returns>
        public static IRelationalStorage CreateInstance(string invariantName, string connectionString)
        {
            if (string.IsNullOrWhiteSpace(invariantName))
            {
                throw new ArgumentException("The name of invariant must contain characters", nameof(invariantName));
            }

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException("Connection string must contain characters", nameof(connectionString));
            }

            return new RelationalStorage(invariantName, connectionString);
        }

        /// <summary>
        /// Creates an instance of a database of type <see cref="IRelationalStorage"/>.
        /// </summary>
        /// <param name="invariantName">The invariant name of the connector for this database.</param>
        /// <param name="dataSource">The data source used to open database connections.</param>
        /// <returns>A relational storage instance.</returns>
        public static IRelationalStorage CreateInstance(string invariantName, DbDataSource dataSource)
        {
            if (string.IsNullOrWhiteSpace(invariantName))
            {
                throw new ArgumentException("The name of invariant must contain characters", nameof(invariantName));
            }

View on GitHub (pinned to fca799fa70)

Solutions

  1. Provide a valid ADO.NET connection string, e.g. 'Server=...;Database=...;User Id=...;Password=...'.
  2. Bind connection string from IConfiguration / options and verify it is non-empty at startup before constructing storage.
  3. Resolve the connection string from your secrets manager (Key Vault, user-secrets) and log its presence (not its value) for diagnostics.
  4. If using DbDataSource instead, switch to the CreateInstance(invariantName, dataSource) overload.

Example fix

// before
var storage = RelationalStorage.CreateInstance("System.Data.SqlClient", "  ");

// after
var cs = config.GetConnectionString("OrleansStorage")
    ?? throw new InvalidOperationException("OrleansStorage connection string missing.");
var storage = RelationalStorage.CreateInstance("System.Data.SqlClient", cs);
Defensive patterns

Strategy: validation

Validate before calling

var cs = config.GetConnectionString("OrleansStorage")
    ?? throw new InvalidOperationException("Connection string 'OrleansStorage' missing.");
if (string.IsNullOrWhiteSpace(cs)) throw new InvalidOperationException("Empty connection string.");

Type guard

static bool HasConnectionString(string? s) => !string.IsNullOrWhiteSpace(s);

Try / catch

try { storage = RelationalStorage.CreateInstance(inv, cs); }
catch (ArgumentException ex) when (ex.ParamName == nameof(cs)) { /* load secret */ }

Prevention

When it happens

Trigger: Calling CreateInstance with a populated invariant but a missing/blank connection string. Typical when the connection string key is misspelled in config or the secrets provider returned empty.

Common situations: Connection string not injected from Azure Key Vault / environment variables in production; wrong config key name (e.g. 'ConnectionString' vs 'connectionString'); empty value left during local-to-prod migration; user-secrets not loaded in Development.

Related errors


AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13). Data as JSON: /api/errors/55a057a6560ac3b1. Report an issue: GitHub.