{"record":{"id":"c978b694c027f0c1","repo":"hasura/graphql-engine","slug":"run-sql-api-request-failed-d","errorCode":null,"errorMessage":"run_sql api request failed %d","messagePattern":"run_sql api request failed (.+?)","errorType":"http","errorClass":"errors.Error","httpStatus":null,"severity":"error","filePath":"cli/internal/hasura/sourceops/mssql/run_sql.go","lineNumber":35,"sourceCode":"\t\tType: \"mssql_run_sql\",\n\t\tArgs: input,\n\t}\n\n\tb := new(bytes.Buffer)\n\n\tresp, err := c.send(body, b)\n\tif err != nil {\n\t\treturn nil, errors.E(op, err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tif b.Len() > 0 {\n\t\t\treturn nil, errors.E(op, errors.KindHasuraAPI, b.String())\n\t\t} else {\n\t\t\treturn nil, errors.E(\n\t\t\t\top,\n\t\t\t\terrors.KindHasuraAPI,\n\t\t\t\tfmt.Errorf(\"run_sql api request failed %d\", resp.StatusCode),\n\t\t\t)\n\t\t}\n\t}\n\n\to := new(hasura.MSSQLRunSQLOutput)\n\n\terr = json.NewDecoder(b).Decode(o)\n\tif err != nil {\n\t\treturn nil, errors.E(op, err)\n\t}\n\n\treturn o, nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":49,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/internal/hasura/sourceops/mssql/run_sql.go#L17-L49","documentation":"MSSQLRunSQL returns this error when the Hasura server answers the mssql_run_sql metadata API call with a non-200 HTTP status and an empty body, so only the status code is included in the message. It is wrapped with errors.KindHasuraAPI, distinguishing a server rejection from a network/transport error produced earlier in Send.","triggerScenarios":"Running migrations (InsertVersion/SetVersion etc. via mssql_run_sql) against a MSSQL source where Hasura replies 401/403 (admin secret mismatch), 404 (mssql source kind unsupported), or 5xx empty-body (SQL Server unreachable, auth failure, or driver-level error such as TLS/encryption mismatch).","commonSituations":"SQL Server credentials wrong or login locked out, server forcing encryption the driver can't negotiate, Hasura pointing at wrong host/instance/port, wrong admin secret, or version mismatch between CLI and server for the mssql_run_sql endpoint.","solutions":["Use the embedded status code: 401/403 → fix admin secret; 404 → confirm mssql support; 5xx → read Hasura + SQL Server logs","Verify SQL Server connectivity and auth from the Hasura host (sqlcmd with same params, check encryption settings)","Run the CLI with --debug to capture the request/response since the body is empty","Confirm the mssql source entry in metadata and resolve inconsistencies","Upgrade CLI/server to versions that both support mssql_run_sql"],"exampleFix":"// before\nout, err := c.MSSQLRunSQL(args)\nif err != nil { return err }\n\n// after\nout, err := c.MSSQLRunSQL(args)\nif err != nil {\n  if strings.Contains(err.Error(), \"run_sql api request failed\") {\n    return fmt.Errorf(\"mssql_run_sql rejected; check server and SQL Server logs: %w\", err)\n  }\n  return err\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight SQL Server connectivity with the same params Hasura uses\n// sqlcmd -S host,1433 -U user -P pass -Q \"SELECT 1\" before migrate apply","typeGuard":"func isEmptyBodyAPIError(err error) bool {\n  return err != nil && strings.Contains(err.Error(), \"api request failed\")\n}","tryCatchPattern":"out, err := c.MSSQLRunSQL(args)\nif err != nil {\n  if isEmptyBodyAPIError(err) {\n    return diagnoseFromStatus(err)\n  }\n  return err\n}","preventionTips":["Check SQL Server encryption settings match the server config","Ensure the DB role can create hdb_catalog objects","Keep admin secret in env config, not CLI flags"],"tags":["hasura","mssql","sql-server","run-sql","http-status","api-error","go"],"backgroundTag":"hasura-metadata-api-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}