{"record":{"id":"f752cdbdfabae6fb","repo":"hasura/graphql-engine","slug":"cannot-find-database-config-db","errorCode":null,"errorMessage":"Cannot find database ${config.db}","messagePattern":"Cannot find database (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"dc-agents/reference/src/index.ts","lineNumber":92,"sourceCode":"    return getSchema(staticData, config, request.body);\n  },\n);\n\nserver.post<{ Body: QueryRequest; Reply: QueryResponse }>(\n  '/query',\n  async (request, _response) => {\n    server.log.info(\n      { headers: request.headers, query: request.body },\n      'query.request',\n    );\n\n    const config = getConfig(request);\n    const dbStoreName = config.db\n      ? getDbStoreName(config.db)\n      : defaultDbStoreName;\n\n    if (!(dbStoreName in staticData))\n      throw new Error(`Cannot find database ${config.db}`);\n\n    const data = filterAvailableTables(staticData[dbStoreName], config);\n    return queryData(getTable(data, config), request.body);\n  },\n);\n\n// Methods on dataset resources.\n//\n// Examples:\n//\n// > curl -H 'content-type: application/json' -XGET localhost:8100/datasets/templates/Chinook\n// {\"exists\": true}\n//\nserver.get<{ Params: { name: string }; Reply: DatasetGetTemplateResponse }>(\n  '/datasets/templates/:name',\n  async (request, _response) => {\n    server.log.info(\n      { headers: request.headers, query: request.body },","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/dc-agents/reference/src/index.ts#L74-L110","documentation":"This error is thrown by the /query route of the Hasura Data Connector reference agent when the database named in the request config cannot be found in the server's loaded static data. The config comes from the X-Hasura-DataConnector-Config header, and config.db is resolved (prefixed with getDbStoreName) to a key in the staticData map populated at startup via loadStaticData. If no matching entry exists, the request is rejected before any query runs.","triggerScenarios":"Sending a POST /query with a config header whose db field names a dataset that was never loaded — e.g. {\"db\":\"foo\"} when staticData only contains the default store or \"$foo\"-prefixed clones created via /datasets/clones. Also occurs if the server was started with different templates/clone directories than the client expects, or if db is misspelled.","commonSituations":"Config header mismatch between Hasura DDN and the connector agent; querying a clone before it is created (clone names are stored with a '$' prefix via getDbStoreName); running the agent against a different working directory so static data loads nothing; typos in the db config value.","solutions":["Check the value of the X-Hasura-DataConnector-Config header's db field and confirm it matches an entry the server loaded (inspect server startup logs / loadStaticData output).","For clones, create the dataset first via POST /datasets/clones/{name} with {\"from\":\"<template>\"}; the config then uses the returned db value (e.g. \"$foo\").","List available templates via GET /datasets/templates/{name} to verify the database name exists.","If the server loaded nothing, restart the agent ensuring the static data directory/DB environment is correctly configured so loadStaticData populates staticData."],"exampleFix":"// before\nawait fetch('http://localhost:8100/query', {\n  headers: { 'X-Hasura-DataConnector-Config': JSON.stringify({ db: 'foo' }) },\n  method: 'POST',\n  body: JSON.stringify(query),\n});\n\n// after: create the clone first, then use its returned config\nconst clone = await fetch('http://localhost:8100/datasets/clones/foo', {\n  method: 'POST',\n  headers: { 'content-type': 'application/json' },\n  body: JSON.stringify({ from: 'Chinook' }),\n}).then(r => r.json());\n// clone.config.db === '$foo'\nawait fetch('http://localhost:8100/query', {\n  headers: { 'X-Hasura-DataConnector-Config': JSON.stringify(clone.config) },\n  method: 'POST',\n  body: JSON.stringify(query),\n});","handlingStrategy":"validation","validationCode":"const config = JSON.parse(headerValue);\nconst dbStoreName = config.db ? `$${config.db.replace(/^\\$/, '')}` : undefined;\nconst exists = await fetch(`http://localhost:8100/datasets/templates/${name}`).then(r => r.json());\nif (!exists) throw new Error('dataset not available');","typeGuard":"const isValidDbConfig = (c: unknown): c is { db: string } =>\n  typeof c === 'object' && c !== null && typeof (c as any).db === 'string';","tryCatchPattern":"try { await queryAgent(config, query); } catch (e) { if (e instanceof Error && e.message.startsWith('Cannot find database')) { /* recreate clone or fix config header */ } throw e; }","preventionTips":["Verify dataset existence via GET /datasets/templates/:name before querying","Create clones through POST /datasets/clones/:name and reuse the returned config verbatim","Log the X-Hasura-DataConnector-Config header value when debugging connector requests"],"tags":["hasura","data-connector","config","database-not-found"],"backgroundTag":"unknown-database-in-config","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}