{"record":{"id":"edcec6bc0caa4198","repo":"googleapis/mcp-toolbox","slug":"errors-encountered-during-query-execution-or-row-p-edcec6","errorCode":null,"errorMessage":"errors encountered during query execution or row processing: %w","messagePattern":"errors encountered during query execution or row processing: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/mssql/mssql.go","lineNumber":149,"sourceCode":"\t\t}\n\n\t\tfor results.Next() {\n\t\t\tscanErr := results.Scan(values...)\n\t\t\tif scanErr != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"unable to parse row: %w\", scanErr)\n\t\t\t}\n\t\t\trow := orderedmap.Row{}\n\t\t\tfor i, name := range cols {\n\t\t\t\trow.Add(name, rawValues[i])\n\t\t\t}\n\t\t\tout = append(out, row)\n\t\t}\n\t}\n\n\t// Check for errors from iterating over rows or from the query execution itself.\n\t// results.Close() is handled by defer.\n\tif err := results.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"errors encountered during query execution or row processing: %w\", err)\n\t}\n\n\treturn out, nil\n}\n\nfunc initMssqlConnection(\n\tctx context.Context,\n\ttracer trace.Tracer,\n\tname, host, port, user, pass, dbname, encrypt string,\n) (\n\t*sql.DB,\n\terror,\n) {\n\t//nolint:all // Reassigned ctx\n\tctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)\n\tdefer span.End()\n\n\tuserAgent, err := util.UserAgentFromContext(ctx)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/mssql/mssql.go#L131-L167","documentation":"This error is returned at the end of `RunSQL` when `results.Err()` reports a deferred error from row iteration or query execution. Unlike the immediate execution error, this catches failures that occur mid-stream — connection dropped while reading rows, context cancellation during iteration, or driver-level stream errors.","triggerScenarios":"Calling RunSQL when the connection drops partway through reading a large result set; context is cancelled while rows are still streaming; driver-level network errors during rows.Next() iteration.","commonSituations":"Timeouts on large SELECTs; network instability between client and SQL Server; server closing the connection (idle kill, failover) mid-result; context cancelled by an upstream request timeout.","solutions":["Unwrap the error and check for context.DeadlineExceeded / connection reset causes","Increase the context timeout or paginate large result sets (OFFSET/FETCH)","Enable connection retry/resilience (connection pool settings)","Check network stability and server logs for dropped connections"],"exampleFix":"// before (one huge query)\nstmt := \"SELECT * FROM big_table\"\n// after (paginated)\nstmt := \"SELECT * FROM big_table ORDER BY id OFFSET 0 ROWS FETCH NEXT 10000 ROWS ONLY\"","handlingStrategy":"retry","validationCode":null,"typeGuard":"func isTransientStreamErr(err error) bool {\n    return errors.Is(err, context.DeadlineExceeded) ||\n        errors.Is(err, io.ErrUnexpectedEOF) ||\n        errors.Is(err, syscall.ECONNRESET)\n}","tryCatchPattern":"res, err := src.RunSQL(ctx, stmt, nil)\nif err != nil && strings.Contains(err.Error(), \"row processing\") {\n    if errors.Is(err, context.DeadlineExceeded) {\n        ctx2, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\n        defer cancel()\n        res, err = src.RunSQL(ctx2, stmt, nil)\n    }\n}","preventionTips":["Size context timeouts to query duration","Paginate large result sets","Enable TCP keepalives","Handle upstream context cancellation gracefully"],"tags":["mssql","sql","network","streaming","timeout"],"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"}