I am working on a project which uses C# .NET5 and Google Big Query to read a CSV file and insert the CSV data into GBQ. However, I got the error:
Errors [
Message[Table 702873453552:my_dataset.my_table not found.] Location[ - ] Reason[notFound] Domain[global]
]
The code I used to create table and insert rows are from google official website:
Create table: https://cloud.google.com/bigquery/docs/samples/bigquery-create-table#bigquery_create_table-csharp
InsertRows: https://cloud.google.com/bigquery/docs/samples/bigquery-table-insert-rows
var table = new BigQueryCreateTable(schema, tableId); table.CreateTable(); using (CsvReader csvr = new CsvReader(reader, CultureInfo.CurrentCulture)) { csvr.Read(); csvr.ReadHeader(); var bigQueryTableInsertRows = new BigQueryTableInsertRows(tableId, projectId); string[] headerRowItems = csvr.Context.Reader.HeaderRecord; var i = 0; ArrayList rows = new ArrayList(); while (csvr.Read()) { var key = ""; var value = ""; var j = 0; var bigQueryRow = new BigQueryInsertRow($"{i}") while (j < headerRowItems.Length) { key = headerRowItems[j]; value = csvr.GetField<string>(headerRowItems[j]); bigQueryRow.Add(key, value); j++; } i++; rows.Add(bigQueryRow); } var rowArr = rows.ToArray(typeof(BigQueryInsertRow)) as BigQueryInsertRow[]; **bigQueryTableInsertRows.TableInsertRows(rowArr);** }
Sometimes, it will not find the table and throw the error. However, it does not happen all the time. Just sometimes.
What could be the issue?