{"record":{"id":"f1469f74ff1015e3","repo":"googleapis/mcp-toolbox","slug":"errors-encountered-during-query-execution-or-row-p","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/cloudsqlmssql/cloud_sql_mssql.go","lineNumber":151,"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 initCloudSQLMssqlConnection(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {\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)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Create dsn\n\tquery := url.Values{}\n\tquery.Add(\"app name\", userAgent)","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqlmssql/cloud_sql_mssql.go#L133-L169","documentation":"Returned by the cloud-sql-mssql source's RunSQL after row iteration completes, when results.Err() reports a deferred error from the query execution or the row-iteration stream. Unlike a Scan failure, this catches errors surfaced lazily by the driver after streaming rows (e.g. server-side execution errors on multi-result statements or mid-stream connection loss). It is the last chance error check before results are returned.","triggerScenarios":"QueryContext returned a result set, Columns() succeeded (or was tolerated for DDL/DML), but results.Err() is non-nil after iteration — server-side error raised during result consumption (e.g. statement with multiple result sets where a later one fails, lock/timeout during streaming, connection reset).","commonSituations":"Batch/multi-statement SQL where an earlier statement succeeds and a later one fails, long-running result streams interrupted by network blips, query timeouts surfacing only after partial reads, deadlocks encountered mid-iteration.","solutions":["Read the wrapped error for the server-side SQL error number and message","Split multi-statement batches into separate RunSQL calls to isolate the failing statement","Add retry logic for transient errors (deadlock error 1205, timeouts)","Tune query timeout / resource settings if statements are killed by the server","Check instance logs in Cloud SQL for the server-side error"],"exampleFix":"// before\nstatement: \"INSERT INTO t VALUES (1); SELECT * FROM nonexistent_table;\"\n// after\nstatement: \"INSERT INTO t VALUES (1);\"  // run separately\n// and a second call: \"SELECT * FROM existing_table;\"","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := src.RunSQL(ctx, statement, params)\nif err != nil && strings.Contains(err.Error(), \"query execution or row processing\") {\n    if isTransient(err) { // e.g. deadlock 1205 or timeout\n        time.Sleep(backoff)\n        out, err = src.RunSQL(ctx, statement, params)\n    }\n}","preventionTips":["Keep tool statements to a single statement so failures are isolated and diagnosable","Enable retry with backoff for transient SQL Server errors (deadlock 1205, timeouts)","Check Cloud SQL instance logs when streaming errors recur","Avoid holding transactions/locks that span long result streams"],"tags":["mssql","sql","result-iteration","cloudsql"],"backgroundTag":"query-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}