{"record":{"id":"9660b120bab78af5","repo":"tursodatabase/turso","slug":"column-name-was-not-found","errorCode":null,"errorMessage":"Column {name} was not found.","messagePattern":"Column (.+?) was not found\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteDataReader.cs","lineNumber":390,"sourceCode":"\n        string? match = null;\n        var matchOrdinal = -1;\n        for (var i = 0; i < FieldCount; i++)\n        {\n            if (string.Equals(GetName(i), name, StringComparison.OrdinalIgnoreCase))\n            {\n                if (match is not null)\n                    throw new InvalidOperationException(Properties.Resources.AmbiguousColumnName(name, match, GetName(i)));\n\n                match = GetName(i);\n                matchOrdinal = i;\n            }\n        }\n\n        if (match is not null)\n            return matchOrdinal;\n\n        throw new ArgumentOutOfRangeException(nameof(name), name, $\"Column {name} was not found.\");\n    }\n\n    public override DataTable GetSchemaTable()\n    {\n        EnsureOpen();\n        var statement = GetStatement();\n        var schema = new DataTable(\"SchemaTable\");\n        schema.Columns.Add(SchemaTableColumn.ColumnName, typeof(string));\n        schema.Columns.Add(SchemaTableColumn.ColumnOrdinal, typeof(int));\n        schema.Columns.Add(SchemaTableColumn.ColumnSize, typeof(int));\n        schema.Columns.Add(SchemaTableColumn.NumericPrecision, typeof(short));\n        schema.Columns.Add(SchemaTableColumn.NumericScale, typeof(short));\n        schema.Columns.Add(SchemaTableColumn.IsUnique, typeof(bool));\n        schema.Columns.Add(SchemaTableColumn.IsKey, typeof(bool));\n        schema.Columns.Add(\"BaseServerName\", typeof(string));\n        schema.Columns.Add(\"BaseCatalogName\", typeof(string));\n        schema.Columns.Add(SchemaTableColumn.BaseColumnName, typeof(string));\n        schema.Columns.Add(SchemaTableColumn.BaseSchemaName, typeof(string));","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data.Sqlite/SqliteDataReader.cs#L372-L408","documentation":"ArgumentOutOfRangeException thrown by GetOrdinal when no column matches the requested name either case-sensitively or case-insensitively. The reader exposes only the columns of the current result set, so the name must appear in the executed query's projection — table columns that were not selected are not addressable. Note GetOrdinal does not throw for duplicate names (first match wins); it throws only for no match at all.","triggerScenarios":"GetOrdinal(\"Name\") when the query selected only Id; typos and casing mistakes like GetOrdinal(\"EMail\") for a column named Email; queries changed (column renamed/aliased) while the reading code kept the old name; calling GetOrdinal for a column of a different result set after NextResult().","commonSituations":"Schema evolution renaming columns without updating reader code; SELECT * combined with column reordering plus name typos; stored query text drifting from the C# mapping after merges.","solutions":["Run the query and inspect reader.GetName(0..FieldCount-1) (or EXPLAIN the projection) to see the actual column names, including aliases.","Select columns explicitly (no SELECT *) and alias them to the exact names the code reads.","Resolve ordinals once per query into variables, and add a startup smoke test that runs the query against a test database so renames fail in CI, not production."],"exampleFix":"// before\nvar i = reader.GetOrdinal(\"CustomerName\"); // column is aliased AS name\n\n// after\nvar i = reader.GetOrdinal(\"name\"); // match the alias/name in the SELECT list","handlingStrategy":"validation","validationCode":"bool HasColumn(SqliteDataReader r, string name)\n    => Enumerable.Range(0, r.FieldCount).Any(i => r.GetName(i) == name);","typeGuard":null,"tryCatchPattern":"try { var i = reader.GetOrdinal(name); }\ncatch (ArgumentOutOfRangeException) { /* column really absent: log schema drift, fail that field */ }","preventionTips":["Select explicit column lists with stable aliases instead of SELECT *.","Add CI tests that run each query against a dev database so renamed columns break the build, not production."],"tags":["csharp","dotnet","sqlite","data-reader","column-mapping"],"backgroundTag":"column-not-found","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}