Manage connections

This document describes how to view, list, share, edit, delete, andtroubleshoot a BigQuery connection.

As a BigQuery administrator, you can create and manageconnections that are used to connect to services and external data sources.BigQuery analysts use these connections to submit queriesagainst external data sources without moving or copying data intoBigQuery. You can create the following types of connections:

To create a default connection for a project, see theDefault connection overview.

Before you begin

Required roles

To get the permissions that you need to manage connections, ask your administrator to grant you the following IAM roles:

For more information about granting roles, seeManage access to projects, folders, and organizations.

You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

For information about the roles needed to create and use a defaultconnection, seeRequired roles and permissions.

These predefined roles contain the permissions required to perform the tasks inthis document. To see the exact permissions that are required, expand theRequired permissions section:

Required permissions

  • View connection details:bigquery.connections.get
  • List all connections:bigquery.connections.list
  • Edit and delete a connection:bigquery.connections.update
  • Share a connection:bigquery.connections.setIamPolicy

List all connections

Select one of the following options:

Console

  1. Go to theBigQuery page.

    Go to BigQuery

    Connections are listed in your project, in a group calledConnections.

  2. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

    If you don't see the left pane, clickExpand left pane to open the pane.

  3. In theExplorer pane, click your project name, and then clickConnections to see a list of all connections.

bq

Enter thebq ls command and specify the--connection flag. Optionally,specify the--project_id and--location flags to identify the projectand location of the connections to be listed.

bq ls --connection --project_id=PROJECT_ID --location=REGION

Replace the following:

API

Use theprojects.locations.connections.list methodin the REST API reference section.

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_connection_v1deflist_connections(project_id:str,location:str):"""Prints all connections in a given project and location.    Args:        project_id: The Google Cloud project ID.        location: The geographic location of the connections (for example, "us", "us-central1").    """client=bigquery_connection_v1.ConnectionServiceClient()parent=client.common_location_path(project_id,location)request=bigquery_connection_v1.ListConnectionsRequest(parent=parent,page_size=100,)print(f"Listing connections in project '{project_id}' and location '{location}':")try:forconnectioninclient.list_connections(request=request):print(f"Connection ID:{connection.name.split('/')[-1]}")print(f"Friendly Name:{connection.friendly_name}")print(f"Has Credential:{connection.has_credential}")print("-"*20)print("Finished listing connections.")exceptgoogle.api_core.exceptions.InvalidArgumentase:print(f"Could not list connections. Please check that the project ID '{project_id}' "f"and location '{location}' are correct. Details:{e}")

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

const{ConnectionServiceClient}=require('@google-cloud/bigquery-connection');const{status}=require('@grpc/grpc-js');constclient=newConnectionServiceClient();/** * Lists BigQuery connections in a given project and location. * * @param {string} projectId The Google Cloud project ID. for example, 'example-project-id' * @param {string} location The location to list connections for. for example, 'us-central1' */asyncfunctionlistConnections(projectId,location){constparent=client.locationPath(projectId,location);constrequest={parent,pageSize:100,};try{const[connections]=awaitclient.listConnections(request,{autoPaginate:false,});if(connections.length===0){console.log(`No connections found in${location} for project${projectId}.`,);return;}console.log('Connections:');for(constconnectionofconnections){console.log(`  Name:${connection.name}`);console.log(`  Friendly Name:${connection.friendlyName}`);}}catch(err){if(err.code===status.NOT_FOUND){console.log(`Project '${projectId}' or location '${location}' not found.`,);}else{console.error('Error listing connections:',err);}}}

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.connection.v1.ListConnectionsRequest;importcom.google.cloud.bigquery.connection.v1.LocationName;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importjava.io.IOException;// Sample to get list of connectionspublicclassListConnections{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";Stringlocation="MY_LOCATION";listConnections(projectId,location);}staticvoidlistConnections(StringprojectId,Stringlocation)throwsIOException{try(ConnectionServiceClientclient=ConnectionServiceClient.create()){LocationNameparent=LocationName.of(projectId,location);intpageSize=10;ListConnectionsRequestrequest=ListConnectionsRequest.newBuilder().setParent(parent.toString()).setPageSize(pageSize).build();client.listConnections(request).iterateAll().forEach(con->System.out.println("Connection Id :"+con.getName()));}}}

View connection details

After you create a connection, you can get information about theconnection's configuration. The configuration includes the values yousupplied when you created the transfer.

Select one of the following options:

Console

  1. Go to theBigQuery page.

    Go to BigQuery

  2. Connections are listed in your project, in a group calledConnections.

  3. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

  4. In theExplorer pane, click your project name, and then clickConnections to see a list of all connections.

  5. Click the connection to see the details.

bq

Enter thebq show command and specify the--connection flag. Optionally,qualify the connection ID with the project ID and region of the connection.

bq show --connectionPROJECT_ID.REGION.CONNECTION_ID

Replace the following:

  • PROJECT_ID: your Google Cloud project ID
  • REGION: theconnection region
  • CONNECTION_ID: the connection ID

API

Use theprojects.locations.connections.get methodin the REST API reference section.

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_connection_v1client=bigquery_connection_v1.ConnectionServiceClient()defget_connection(project_id:str,location:str,connection_id:str):"""Retrieves connection metadata about a specified BigQuery connection.    A connection stores metadata about an external data source and credentials to access it.    Args:        project_id: The Google Cloud project ID.        location: The geographic location of the connection (for example, "us-central1").        connection_id: The ID of the connection to retrieve.    """name=client.connection_path(project_id,location,connection_id)try:connection=client.get_connection(name=name)print(f"Successfully retrieved connection:{connection.name}")print(f"Friendly name:{connection.friendly_name}")print(f"Description:{connection.description}")ifconnection.cloud_sql:print(f"Cloud SQL instance ID:{connection.cloud_sql.instance_id}")exceptgoogle.api_core.exceptions.NotFound:print(f"Connection '{name}' not found.")

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

const{ConnectionServiceClient}=require('@google-cloud/bigquery-connection').v1;const{status}=require('@grpc/grpc-js');constclient=newConnectionServiceClient();/** * Retrieves connection metadata about a specified BigQuery connection. * * A connection stores metadata about an external data source and credentials to access it. * * @param {string} projectId - Google Cloud project ID. for example, 'example-project-id' * @param {string} location - The location of the connection. for example, 'us-central1' * @param {string} connectionId - The ID of the connection to retrieve. for example, 'example_connection' */asyncfunctiongetConnection(projectId,location,connectionId){constname=client.connectionPath(projectId,location,connectionId);constrequest={name,};try{const[connection]=awaitclient.getConnection(request);console.log(`Successfully retrieved connection:${connection.name}`);console.log(`  Friendly name:${connection.friendlyName}`);console.log(`  Description:${connection.description}`);console.log(`  Has credential:${connection.hasCredential}`);if(connection.cloudSql){console.log(`  Cloud SQL instance ID:${connection.cloudSql.instanceId}`);console.log(`  Cloud SQL database:${connection.cloudSql.database}`);console.log(`  Cloud SQL type:${connection.cloudSql.type}`);}}catch(err){if(err.code===status.NOT_FOUND){console.log(`Connection${name} not found.`);}else{console.error(`Error getting connection${name}:`,err);}}}

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.connection.v1.Connection;importcom.google.cloud.bigquery.connection.v1.ConnectionName;importcom.google.cloud.bigquery.connection.v1.GetConnectionRequest;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importjava.io.IOException;// Sample to get connectionpublicclassGetConnection{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";Stringlocation="MY_LOCATION";StringconnectionId="MY_CONNECTION_ID";getConnection(projectId,location,connectionId);}staticvoidgetConnection(StringprojectId,Stringlocation,StringconnectionId)throwsIOException{try(ConnectionServiceClientclient=ConnectionServiceClient.create()){ConnectionNamename=ConnectionName.of(projectId,location,connectionId);GetConnectionRequestrequest=GetConnectionRequest.newBuilder().setName(name.toString()).build();Connectionresponse=client.getConnection(request);System.out.println("Connection info retrieved successfully :"+response.getName());}}}

Get the Identity and Access Management (IAM) policy for a connection

Follow these steps to get the IAM policy for a connection:

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_connection_v1client=bigquery_connection_v1.ConnectionServiceClient()defget_connection_iam_policy(project_id:str,location:str,connection_id:str,):"""Gets the IAM policy of a connection.    Args:        project_id: The Google Cloud project ID.        location: The geographic location of the connection (for example, "us").        connection_id: The ID of the connection.    """resource=client.connection_path(project_id,location,connection_id)try:policy=client.get_iam_policy(resource=resource)print(f"Successfully retrieved IAM policy for connection:{resource}")ifnotpolicy.bindings:print("This policy is empty and has no bindings.")forbindinginpolicy.bindings:print(f"Role:{binding.role}")print("Members:")formemberinbinding.members:print(f"    -{member}")exceptgoogle.api_core.exceptions.NotFound:print(f"Connection not found:{resource}")

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

const{ConnectionServiceClient}=require('@google-cloud/bigquery-connection').v1;const{status}=require('@grpc/grpc-js');constclient=newConnectionServiceClient();/** * Gets the IAM policy for a BigQuery connection. * @param {string} projectId Google Cloud project ID (for example, 'example-project-id'). * @param {string} location The location of the connection (for example, 'us'). * @param {string} connectionId The connection ID (for example, 'example-connection'). */asyncfunctiongetIamPolicy(projectId,location,connectionId){constresource=client.connectionPath(projectId,location,connectionId);constrequest={resource,};try{const[policy]=awaitclient.getIamPolicy(request);console.log(`Successfully retrieved IAM policy for connection:${connectionId}`,);if(policy.bindings &&policy.bindings.length >0){console.log('Bindings:');policy.bindings.forEach(binding=>{console.log(`  Role:${binding.role}`);console.log('  Members:');binding.members.forEach(member=>{console.log(`    -${member}`);});});}else{console.log('No policy bindings found.');}}catch(err){if(err.code===status.NOT_FOUND){console.log(`Connection '${connectionId}' not found in project '${projectId}' at location '${location}'.`,);}else{console.error('An error occurred while getting the IAM policy:',err);}}}

Share a connection with users

You can grant the following roles to let users query data and manage connections:

  • roles/bigquery.connectionUser: enables users to use connections to connectwith external data sources and run queries on them.

  • roles/bigquery.connectionAdmin: enables users to manage connections.

For more information about IAM roles and permissions inBigQuery, seePredefined roles and permissions.

Select one of the following options:

Console

  1. Go to theBigQuery page.

    Go to BigQuery

    Connections are listed in your project, in a group calledConnections.

  2. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

    If you don't see the left pane, clickExpand left pane to open the pane.

  3. Click your project, clickConnections, and then select a connection.

  4. In theDetails pane, clickShare to share a connection.Then do the following:

    1. In theConnection permissions dialog, share theconnection with other principals by adding or editingprincipals.

    2. ClickSave.

bq

You cannot share a connection with the bq command-line tool.To share a connection, use the Google Cloud console orthe BigQuery Connections API method to share a connection.

API

Use theprojects.locations.connections.setIAM methodin the BigQuery Connections REST API reference section, andsupply an instance of thepolicy resource.

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.api.resourcenames.ResourceName;importcom.google.cloud.bigquery.connection.v1.ConnectionName;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importcom.google.iam.v1.Binding;importcom.google.iam.v1.Policy;importcom.google.iam.v1.SetIamPolicyRequest;importjava.io.IOException;// Sample to share connectionspublicclassShareConnection{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";Stringlocation="MY_LOCATION";StringconnectionId="MY_CONNECTION_ID";shareConnection(projectId,location,connectionId);}staticvoidshareConnection(StringprojectId,Stringlocation,StringconnectionId)throwsIOException{try(ConnectionServiceClientclient=ConnectionServiceClient.create()){ResourceNameresource=ConnectionName.of(projectId,location,connectionId);Bindingbinding=Binding.newBuilder().addMembers("group:example-analyst-group@google.com").setRole("roles/bigquery.connectionUser").build();Policypolicy=Policy.newBuilder().addBindings(binding).build();SetIamPolicyRequestrequest=SetIamPolicyRequest.newBuilder().setResource(resource.toString()).setPolicy(policy).build();client.setIamPolicy(request);System.out.println("Connection shared successfully");}}}

Edit a connection

A connection uses the credentials of the user who created it. If you need tochange the user attached to a connection, you can update theuser's credentials. This is useful if the user who created the connection isno longer with your organization.

You cannot edit the following elements of a connection:

  • Connection type
  • Connection ID
  • Location

Select one of the following options:

Console

  1. Go to theBigQuery page.

    Go to BigQuery

    Connections are listed in your project,in a group calledConnections.

  2. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

  3. In theExplorer pane, click your project name, and then clickConnections to see a list of all connections.

  4. To see the details, click the connection.

  5. In theConnection info section, clickEdit details. Then do the following:

    1. In theEdit connection dialog, edit the connection detailsincluding the user credentials.

    2. ClickUpdate connection.

bq

Enter thebq update command and supply the connection flag:--connection. The fully qualifiedconnection_id is required.

  bq update --connection --connection_type='CLOUD_SQL'      --properties='{"instanceId" : "INSTANCE",      "database" : "DATABASE", "type" : "MYSQL" }'      --connection_credential='{"username":"USERNAME", "password":"PASSWORD"}'PROJECT.REGION.CONNECTION_ID

Replace the following:

  • INSTANCE: the Cloud SQL instance
  • DATABASE: the database name
  • USERNAME: the username of your Cloud SQL database
  • PASSWORD: the password to your Cloud SQL database
  • PROJECT: the Google Cloud project ID
  • REGION: theconnection region
  • CONNECTION_ID: the connection ID

For example, the following command updates the connection in aproject with the IDfederation-test and connection IDtest-mysql.

bq update --connection --connection_type='CLOUD_SQL'    --properties='{"instanceId" : "federation-test:us-central1:new-mysql",    "database" : "imdb2", "type" : "MYSQL" }'    --connection_credential='{"username":"my_username",    "password":"my_password"}' federation-test.us.test-mysql

API

See theprojects.locations.connections.patch methodin the REST API reference section, and supply an instance of theconnection.

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_connection_v1fromgoogle.protobufimportfield_mask_pb2client=bigquery_connection_v1.ConnectionServiceClient()defupdate_connection(project_id:str,location:str,connection_id:str):"""Updates a BigQuery connection's friendly name and description.    For security reasons, updating connection properties also resets the    credential. The `update_mask` specifies which fields of the connection    to update. This sample only updates metadata fields to avoid resetting    credentials.    Args:        project_id: The Google Cloud project ID.        location: The geographic location of the connection (for example, "us-central1").        connection_id: The ID of the connection to update.    """connection_name=client.connection_path(project_id,location,connection_id)connection=bigquery_connection_v1.Connection(friendly_name="Example Updated BigQuery Connection",description="This is an updated description for the connection.",)update_mask=field_mask_pb2.FieldMask(paths=["friendly_name","description"])try:response=client.update_connection(name=connection_name,connection=connection,update_mask=update_mask,)print(f"Connection '{response.name}' updated successfully.")print(f"Friendly Name:{response.friendly_name}")print(f"Description:{response.description}")exceptgoogle.api_core.exceptions.NotFound:print(f"Connection '{connection_name}' not found. Please create it first.")

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

const{ConnectionServiceClient}=require('@google-cloud/bigquery-connection').v1;const{status}=require('@grpc/grpc-js');constconnectionClient=newConnectionServiceClient();/** * Updates a BigQuery connection, demonstrating how to update the friendly name and description. * * @param {string} projectId The Google Cloud project ID. for example, 'example-project-id' * @param {string} location The location of the connection. for example, 'us-central1' * @param {string} connectionId The ID of the connection to update. for example, 'example-connection-id' */asyncfunctionupdateConnection(projectId,location,connectionId){constname=connectionClient.connectionPath(projectId,location,connectionId,);constconnection={friendlyName:'Example Updated Connection',description:'A new description for the connection',};constupdateMask={paths:['friendly_name','description'],};constrequest={name,connection,updateMask,};try{const[response]=awaitconnectionClient.updateConnection(request);console.log(`Connection updated:${response.name}`);console.log(`  Friendly name:${response.friendlyName}`);console.log(`  Description:${response.description}`);}catch(err){if(err.code===status.NOT_FOUND){console.log(`Connection not found:${name}`);}else{console.error(`Error updating connection${name}:`,err);}}}

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.connection.v1.Connection;importcom.google.cloud.bigquery.connection.v1.ConnectionName;importcom.google.cloud.bigquery.connection.v1.UpdateConnectionRequest;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importcom.google.protobuf.FieldMask;importcom.google.protobuf.util.FieldMaskUtil;importjava.io.IOException;// Sample to update connectionpublicclassUpdateConnection{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";Stringlocation="MY_LOCATION";StringconnectionId="MY_CONNECTION_ID";Stringdescription="MY_DESCRIPTION";Connectionconnection=Connection.newBuilder().setDescription(description).build();updateConnection(projectId,location,connectionId,connection);}staticvoidupdateConnection(StringprojectId,Stringlocation,StringconnectionId,Connectionconnection)throwsIOException{try(ConnectionServiceClientclient=ConnectionServiceClient.create()){ConnectionNamename=ConnectionName.of(projectId,location,connectionId);FieldMaskupdateMask=FieldMaskUtil.fromString("description");UpdateConnectionRequestrequest=UpdateConnectionRequest.newBuilder().setName(name.toString()).setConnection(connection).setUpdateMask(updateMask).build();Connectionresponse=client.updateConnection(request);System.out.println("Connection updated successfully :"+response.getDescription());}}}

Delete a connection

Select one of the following options:

Console

  1. Go to theBigQuery page.

    Go to BigQuery

    Connections are listed in your project,in a group calledConnections.

  2. In the left pane, clickExplorer:

    Highlighted button for the Explorer pane.

  3. In theExplorer pane, click your project name, and then clickConnections to see a list of all connections.

  4. Click the connection to see the details.

  5. In the details pane, clickDelete to delete the connection.

  6. In theDelete connection? dialog, enterdelete to confirmdeletion.

  7. ClickDelete.

bq

Enter thebq rm command and supply the connection flag:--connection. The fully qualifiedconnection_id is required.

bq rm --connectionPROJECT_ID.REGION.CONNECTION_ID

Replace the following:

  • PROJECT_ID: your Google Cloud project ID
  • REGION: theconnection region
  • CONNECTION_ID: the connection ID

API

See theprojects.locations.connections.delete methodin the REST API reference section.

Python

Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importgoogle.api_core.exceptionsfromgoogle.cloudimportbigquery_connection_v1client=bigquery_connection_v1.ConnectionServiceClient()defdelete_connection(project_id:str,location:str,connection_id:str):"""Deletes a BigQuery connection.    Args:        project_id: The Google Cloud project ID.        location: Location of the connection (for example, "us-central1").        connection_id: ID of the connection to delete.    """name=client.connection_path(project_id,location,connection_id)try:client.delete_connection(name=name)print(f"Connection '{connection_id}' was deleted.")exceptgoogle.api_core.exceptions.NotFound:print(f"Connection '{connection_id}' not found.")

Node.js

Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

const{ConnectionServiceClient}=require('@google-cloud/bigquery-connection').v1;const{status}=require('@grpc/grpc-js');constclient=newConnectionServiceClient();/** * Deletes a connection and its associated credentials. * * @param {string} projectId Google Cloud project ID (for example, 'example-project-id'). * @param {string} location The location where the connection resides (for example, 'us-central1'). * @param {string} connectionId The ID of the connection to delete (for example, 'example-connection'). */asyncfunctiondeleteConnection(projectId,location,connectionId){constrequest={name:client.connectionPath(projectId,location,connectionId),};try{awaitclient.deleteConnection(request);console.log(`Connection${connectionId} deleted successfully.`);}catch(error){if(error.code===status.NOT_FOUND){console.log(`Connection${connectionId} does not exist in location${location} of project${projectId}.`,);}else{console.error(`Error deleting connection${connectionId}:`,error);}}}

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.connection.v1.ConnectionName;importcom.google.cloud.bigquery.connection.v1.DeleteConnectionRequest;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importjava.io.IOException;// Sample to delete a connectionpublicclassDeleteConnection{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";Stringlocation="MY_LOCATION";StringconnectionName="MY_CONNECTION_NAME";deleteConnection(projectId,location,connectionName);}staticvoiddeleteConnection(StringprojectId,Stringlocation,StringconnectionName)throwsIOException{try(ConnectionServiceClientclient=ConnectionServiceClient.create()){ConnectionNamename=ConnectionName.of(projectId,location,connectionName);DeleteConnectionRequestrequest=DeleteConnectionRequest.newBuilder().setName(name.toString()).build();client.deleteConnection(request);System.out.println("Connection deleted successfully");}}}

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.