clockworklabs/SpacetimeDB · error · InvalidOperationException
Building DbConnection with a null nameOrAddress. Call WithDa
Error message
Building DbConnection with a null nameOrAddress. Call WithDatabaseName() first.
What it means
The second precondition in DbConnectionBuilder.Build(): the database name or address must be supplied via WithDatabaseName before connecting. Build throws InvalidOperationException when nameOrAddress is still null, after the uri check has passed.
Source
Thrown at sdks/csharp/src/SpacetimeDBClient.cs:37
{
readonly DbConnection conn = new();
string? uri;
string? nameOrAddress;
string? token;
Compression? compression;
bool light;
bool? confirmedReads;
public DbConnection Build()
{
if (uri == null)
{
throw new InvalidOperationException("Building DbConnection with a null uri. Call WithUri() first.");
}
if (nameOrAddress == null)
{
throw new InvalidOperationException("Building DbConnection with a null nameOrAddress. Call WithDatabaseName() first.");
}
conn.Connect(token, uri, nameOrAddress, compression ?? Compression.Brotli, light, confirmedReads);
#if UNITY_5_3_OR_NEWER
if (SpacetimeDBNetworkManager._instance != null)
{
SpacetimeDBNetworkManager._instance.AddConnection(conn);
}
#endif
return conn;
}
public DbConnectionBuilder<DbConnection> WithUri(string uri)
{
this.uri = uri;
return this;
}
public DbConnectionBuilder<DbConnection> WithDatabaseName(string nameOrAddress)View on GitHub (pinned to 524b4487d9)
Solutions
- Call WithDatabaseName("mydb") (database name or published address) before Build()
- Validate required config values up front and fail with your own error naming the missing key
- Centralize builder construction so both WithUri and WithDatabaseName are always supplied together
Example fix
// before
var conn = builder
.WithUri("https://maincloud.spacetimedb.com")
.Build(); // no WithDatabaseName -> throws
// after
var conn = builder
.WithUri("https://maincloud.spacetimedb.com")
.WithDatabaseName(dbName ?? "mydb")
.Build(); Defensive patterns
Strategy: validation
Validate before calling
var dbName = config["SpacetimeDB:Database"];
if (string.IsNullOrWhiteSpace(dbName))
throw new ConfigException("SpacetimeDB:Database is required before building a connection"); Try / catch
try { var conn = builder.Build(); }
catch (InvalidOperationException e) when (e.Message.Contains("null nameOrAddress"))
{ /* resolve the database name and rebuild */ } Prevention
- Centralize builder construction so both required setters always run
- Validate required config keys at application start, not at connect time
When it happens
Trigger: Calling builder.WithUri(...).Build() without WithDatabaseName(...), or the database-name branch being skipped when the value comes from config/env that is unset.
Common situations: Database name moved to an env var that is missing in a deploy environment; typos between WithDatabaseName and a similarly named setter; per-tenant connection loops where one tenant row has a null name.
Related errors
- Building DbConnection with a null uri. Call WithUri() first.
- URI is required to connect to SpacetimeDB
- Database name or address is required to connect to Spacetime
- never types are not yet supported in C# output
- Unsupported --dotnet-version {version}. Supported values: 8,
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/0187af3fd71b9dad.
Report an issue: GitHub.