Class SpannerConnectionStringBuilder (3.9.0)

public sealed class SpannerConnectionStringBuilder : DbConnectionStringBuilder, IDictionary, ICollection, IEnumerable, ICustomTypeDescriptor

A connection string builder for Spanner connection strings. The connection string should be of the form: Data Source=projects/{project}/instances/{instance}/databases/{database};[Host={hostname};][Port={portnumber}]

Inheritance

Object > DbConnectionStringBuilder > SpannerConnectionStringBuilder

Namespace

Google.Cloud.Spanner.Data

Assembly

Google.Cloud.Spanner.Data.dll

Constructors

SpannerConnectionStringBuilder()

public SpannerConnectionStringBuilder()

SpannerConnectionStringBuilder(String, ChannelCredentials)

public SpannerConnectionStringBuilder(string connectionString, ChannelCredentials credentials = null)

Creates a new SpannerConnectionStringBuilder with the given connection string and optional credential.

Parameters
NameDescription
connectionStringString

A connection string of the form Data Source=projects/{project}/instances/{instance}/databases/{database};[Host={hostname};][Port={portnumber}]. Must not be null.

credentialsChannelCredentials

Optionally supplied credential to use for the connection. If not set, then default application credentials will be used. Credentials can be retrieved from a file or obtained interactively. See Google Cloud documentation for more information. May be null.

SpannerConnectionStringBuilder(String, ChannelCredentials, SessionPoolManager)

public SpannerConnectionStringBuilder(string connectionString, ChannelCredentials credentials, SessionPoolManager sessionPoolManager)

Creates a new SpannerConnectionStringBuilder with the given connection string, optional credential, and session pool manager.

Parameters
NameDescription
connectionStringString

A connection string of the form Data Source=projects/{project}/instances/{instance}/databases/{database};[Host={hostname};][Port={portnumber}]. Must not be null.

credentialsChannelCredentials

The credential to use for the connection. May be null.

sessionPoolManagerSessionPoolManager

The session pool manager to use. Must not be null.

Properties

AllowImmediateTimeouts

public bool AllowImmediateTimeouts { get; set; }

Option to allow a timeout of 0 to mean "fail immediately" rather than "continue indefinitely". This is primarily used for testing.

Property Value
TypeDescription
Boolean

CredentialFile

public string CredentialFile { get; set; }

Optional path to a JSON Credential file. If a Credential is not supplied, Cloud Spanner will use Default Application Credentials.

Property Value
TypeDescription
String

DatabaseName

public DatabaseName DatabaseName { get; set; }

The fully-qualified database name parsed from DataSource. May be null, if the data source isn't set, or is invalid, or doesn't contain a database name.

Property Value
TypeDescription
Google.Cloud.Spanner.Common.V1.DatabaseName

DataSource

public string DataSource { get; set; }

DataSource of the Spanner database in the form of 'projects/{project}/instances/{instance}/databases/{database}' or 'projects/{project}/instances/{instance}'.

Property Value
TypeDescription
String

EmulatorDetection

public EmulatorDetection EmulatorDetection { get; set; }

Specifies whether to allow the connection to check for the presence of the emulator environment variable.

Property Value
TypeDescription
EmulatorDetection
Remarks

This property defaults to None, meaning that the environment variable is ignored.

EnableGetSchemaTable

public bool EnableGetSchemaTable { get; set; }

Option to allow SpannerDataReader to return a schema from GetSchemaTable, on supported platforms. Only partial information is available, and when this option is enabled, DbDataAdapter may be overly eager to use the information to create and manage datasets.

Property Value
TypeDescription
Boolean

EndPoint

public string EndPoint { get; }

The endpoint to use to connect to Spanner. If not supplied in the connection string, the default endpoint will be used.

Property Value
TypeDescription
String

Host

public string Host { get; set; }

The TCP Host name to connect to Spanner. If not supplied in the connection string, the default host will be used.

Property Value
TypeDescription
String

Item[String]

public override object this[string keyword] { get; set; }
Parameter
NameDescription
keywordString
Property Value
TypeDescription
Object
Overrides

LogCommitStats

public bool LogCommitStats { get; set; }

Request commit statistics for all read/write transactions throughout the lifetime of the connection and log these.

Property Value
TypeDescription
Boolean
Remarks

Commit statistics that are returned for a transaction are logged using the logger of the connection. Applications can set a custom logger on the connection to log the output to a different destination. LogCommitStats(CommitRequest, CommitResponse)

MaxConcurrentStreamsLowWatermark

public int MaxConcurrentStreamsLowWatermark { get; set; }

The low watermark of max number of concurrent streams in a channel. A new channel will be created once this is reached, until the maximum size of the channel pool is reached. This rarely needs to be modified.

Property Value
TypeDescription
Int32

MaximumGrpcChannels

public int MaximumGrpcChannels { get; set; }

The maximum number of gRPC channels used for connections with the same settings. Defaults to 4.

Property Value
TypeDescription
Int32

Port

public int Port { get; set; }

The TCP port number to connect to Spanner. If not supplied in the connection string, the default port will be used.

Property Value
TypeDescription
Int32

Project

public string Project { get; }

The Spanner Project name parsed from DataSource May be null, if the data source isn't set, or is invalid.

Property Value
TypeDescription
String

SessionPoolManager

public SessionPoolManager SessionPoolManager { get; set; }

The SessionPoolManager to use for server interactions.

Property Value
TypeDescription
SessionPoolManager
Remarks

This property defaults to Default, and most code will not need to change this. It can be convenient for isolation purposes, particularly in testing.

SpannerDatabase

public string SpannerDatabase { get; }

The Spanner Database name parsed from DataSource. May be null, if the data source isn't set, or is invalid, or doesn't contain a database name.

Property Value
TypeDescription
String

SpannerInstance

public string SpannerInstance { get; }

The Spanner Instance name parsed from DataSource May be null, if the data source isn't set, or is invalid.

Property Value
TypeDescription
String

Timeout

public int Timeout { get; set; }

Defines the default values for CommandTimeout and CommitTimeout along with all network operations to a Cloud Spanner database. Defaults to 60 seconds.

Property Value
TypeDescription
Int32
Remarks

Operations sent to the server that take greater than this duration will fail with a SpannerException and error code DeadlineExceeded. A value of '0' normally indicates that no timeout should be used (it waits an infinite amount of time). However, if you specify AllowImmediateTimeouts=true in the connection string, '0' will cause a timeout that expires immediately. This is normally used only for testing purposes.

UseClrDefaultForNull

public bool UseClrDefaultForNull { get; set; }

Option to change between the default handling of null database values (return Value) or the non-standard handling (return the default value for whatever type is requested).

Property Value
TypeDescription
Boolean
Remarks

If this is false (the default), requesting a value from a SpannerDataReader that is null in the database will return Value, which may cause an InvalidCastException if the requested type is not compatible with that value. For arrays and structs, the behavior is slightly different. A null value is used for an array or struct value where the target type permits such a value. Attempting to convert an array value that contains a null element into a .NET array type with a non-nullable element type will cause an InvalidCastException to be thrown. To avoid this, where array elements may be null for value types, use an array with a nullable element type. This allows code to distinguish between a null element in the original data and a value of 0, false etc.

If this is true, requesting a value from a SpannerDataReader that is null in the database will return the default value of the requested type (e.g. 0 or a null reference). That conversion is also used for array elements. For example, converting a Spanner array consisting of 1, null, and 2 into an Int32 array will result in an array containing 1, 0 and 2. This is the behavior from release 1.0 of this package.

This property corresponds with the value of the "UseClrDefaultForNull" part of the connection string.

Methods

WithDatabase(String)

public SpannerConnectionStringBuilder WithDatabase(string database)

Returns a new instance of a SpannerConnectionStringBuilder with the database portion of the DataSource replaced with a new value.

Parameter
NameDescription
databaseString

The new database name. Can be null to open a connection for Ddl commands.

Returns
TypeDescription
SpannerConnectionStringBuilder

A new instance of SpannerConnectionStringBuilder