Database Reference
In-Depth Information
state, ex);
}
// Wait until the "any key" is pressed.
System.Console.ReadKey();
}
}
}
Most of the sample code is boilerplate that you would use to talk to any
data source using ODBC. The BigQuery-specific parts are actually involved
only in creating the connection; because of this, we've separated out the
ConnectionBuilder into its own class that lets you easily create an ODBC
connection to talk to your BigQuery data.
To use the ConnectionBuilder, you need to specify the DSN name; this is the
name of the connection you created in the ODBC setup steps. We created
the DSN as bigquery1 , so we set that as the DSN name. You also need
to specify a catalog, which is the project from which to read the tables.
The code talks about catalogs, which are ODBC terms, but for BigQuery
connections catalogs are synonymous with projects. If you are going to be
reading data from the same project that you want to bill queries to, this is
all the information that you need. However, if you want to bill a different
project, you can set the billing project independently. The final option,
which we don't specify in the following code snippet because we don't use
it, is to turn on Native mode, which can cause the ODBC driver to pass your
queries directly through to BigQuery without modification.
Here is the code that creates a connection to the DSN bigquery1 using the
project publicdata and bills queries to the bigquery-e2e project:
ConnectionBuilder builder = new ConnectionBuilder();
builder.Dsn = "bigquery1";
builder.Catalog = "publicdata";
builder.ExecCatalog = "bigquery-e2e";
OdbcConnection connection = builder.Build();
The ConnectionBuilder takes this information and turns it into the
ODBC connection string DSN=bigquery1; Catalog=publicdata;
ExecCatalog=bigquery-e2e . When you run this code, you should fill in
your own project ID as the builder.Catalog .
Search WWH ::




Custom Search