{"record":{"id":"ea3f68d7403a8cac","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-ea3f68","errorCode":null,"errorMessage":"unable to execute query: %w","messagePattern":"unable to execute query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/mssql/mssql.go","lineNumber":116,"sourceCode":"\nfunc (s *Source) SourceType() string {\n\t// Returns Cloud SQL MSSQL source type\n\treturn SourceType\n}\n\nfunc (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) MSSQLDB() *sql.DB {\n\t// Returns a Cloud SQL MSSQL database connection pool\n\treturn s.Db\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {\n\tresults, err := s.MSSQLDB().QueryContext(ctx, statement, params...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\tdefer results.Close()\n\n\tcols, err := results.Columns()\n\t// If Columns() errors, it might be a DDL/DML without an OUTPUT clause.\n\t// We proceed, and results.Err() will catch actual query execution errors.\n\t// 'out' will remain an empty slice if cols is empty or err is not nil here.\n\tout := []any{}\n\tif err == nil && len(cols) > 0 {\n\t\t// create an array of values for each column, which can be re-used to scan each row\n\t\trawValues := make([]any, len(cols))\n\t\tvalues := make([]any, len(cols))\n\t\tfor i := range rawValues {\n\t\t\tvalues[i] = &rawValues[i]\n\t\t}\n\n\t\tfor results.Next() {\n\t\t\tscanErr := results.Scan(values...)","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/mssql/mssql.go#L98-L134","documentation":"This error wraps a failure from `QueryContext` in the MSSQL source's `RunSQL`. It means the SQL statement itself failed to execute — syntax errors, missing tables/columns, permission denials, timeouts, or connection drops during execution.","triggerScenarios":"Calling RunSQL with a syntactically invalid statement; referencing non-existent tables or columns; selecting from a database the user lacks rights on; query timeout via context cancellation; parameters count/type mismatch.","commonSituations":"Typos in T-SQL; querying a table that exists in another database/schema; running DDL without permissions; context deadline exceeded on long queries; stale connections after server failover.","solutions":["Run the statement in SSMS/Azure Data Studio to reproduce the exact server error","Unwrap the error and inspect mssql.Error number/state for the server-side cause","Check user permissions on the target database/objects","Increase the context timeout for long-running queries","Validate parameter count and types match the statement's placeholders"],"exampleFix":"// before (wrong schema)\nstmt := \"SELECT * FROM users\"\n// after\nstmt := \"SELECT * FROM dbo.users\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isSqlServerErr(err error) bool {\n    var se mssql.Error\n    return errors.As(err, &se)\n}","tryCatchPattern":"res, err := src.RunSQL(ctx, stmt, nil)\nif err != nil {\n    var se mssql.Error\n    if errors.As(err, &se) {\n        return fmt.Errorf(\"SQL Server error %d: %s\", se.Number, se.Message)\n    }\n    if errors.Is(err, context.DeadlineExceeded) {\n        return fmt.Errorf(\"query timed out: %w\", err)\n    }\n    return err\n}","preventionTips":["Test statements in a SQL client first","Use fully qualified schema.table names","Grant least-privilege permissions","Set realistic context deadlines"],"tags":["mssql","sql","query-execution","database"],"backgroundTag":"sql-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}