{"record":{"id":"72453f17ac0c254a","repo":"clockworklabs/SpacetimeDB","slug":"database-name-or-address-is-required-to-connect-to","errorCode":null,"errorMessage":"Database name or address is required to connect to SpacetimeDB","messagePattern":"Database name or address is required to connect to SpacetimeDB","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/sdk/db_connection_builder.ts","lineNumber":269,"sourceCode":"   *\n   * @returns A new `DbConnection` with the parameters set on this `DbConnectionBuilder`.\n   *\n   * @example\n   *\n   * ```ts\n   * const host = \"http://localhost:3000\";\n   * const name_or_address = \"database_name\"\n   * const auth_token = undefined;\n   * DbConnection.builder().withUri(host).withDatabaseName(name_or_address).withToken(auth_token).build();\n   * ```\n   */\n  build(): DbConnection {\n    if (!this.#uri) {\n      throw new Error('URI is required to connect to SpacetimeDB');\n    }\n\n    if (!this.#nameOrAddress) {\n      throw new Error(\n        'Database name or address is required to connect to SpacetimeDB'\n      );\n    }\n    // We could consider making this an `onConnectError` instead of throwing here.\n    // Ideally, it would be a compile time error, but I'm not sure how to accomplish that.\n    ensureMinimumVersionOrThrow(this.remoteModule.versionInfo?.cliVersion);\n\n    return this.dbConnectionCtor({\n      uri: this.#uri,\n      nameOrAddress: this.#nameOrAddress,\n      identity: this.#identity,\n      token: this.#token,\n      emitter: this.#emitter,\n      compression: this.#compression,\n      lightMode: this.#lightMode,\n      confirmedReads: this.#confirmedReads,\n      createWSFn: this.#createWSFn,\n      remoteModule: this.remoteModule,","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/sdk/db_connection_builder.ts#L251-L287","documentation":"DbConnectionBuilder.build() requires a database name or address previously set via withDatabaseName; it checks the private #nameOrAddress field after the URI check. Missing both or just the name produces this error at build time, before any network activity.","triggerScenarios":"Calling build() without .withDatabaseName(nameOrAddress): config that only sets the URI, a name read from an optional config field that is undefined, or a builder assembled by two different modules where one forgot the name.","commonSituations":"Assuming the database name is inferred from the URI; config split across files where the name is only wired in one path; new environment with a different database name variable left empty.","solutions":["Call .withDatabaseName(name) (or the address equivalent) before .build()","Validate required connection config (uri + name) up front and throw a precise config error","Centralize builder assembly in one connection factory"],"exampleFix":"// before\nDbConnection.builder().withUri(uri).build(); // throws: no name/address\n\n// after\nDbConnection.builder().withUri(uri).withDatabaseName('mydb').build();","handlingStrategy":"validation","validationCode":"const nameOrAddress = process.env.SPACETIMEDB_DATABASE;\nif (!uri || !nameOrAddress) {\n  throw new Error('connection config incomplete: need both uri and database name');\n}\nDbConnection.builder().withUri(uri).withDatabaseName(nameOrAddress).build();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set both withUri and withDatabaseName in the same factory function","Treat empty-string config as missing, not as a valid name","Add startup assertions for all required connection fields"],"tags":["connection","configuration","builder","typescript"],"backgroundTag":"missing-required-config","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}