# Class NpgsqlDataSource

Namespace
  Npgsql

Assembly
  Npgsql.dll

Represents a data source which can be used to obtain open connections, and against which commands can be executed directly.

    public abstract class NpgsqlDataSource : DbDataSource, IDisposable, IAsyncDisposable

Inheritance
  object
  DbDataSource
  NpgsqlDataSource

Implements
  IDisposable
  IAsyncDisposable

Derived
  NpgsqlMultiHostDataSource

Inherited Members
  DbDataSource.Dispose()
  DbDataSource.DisposeAsync()
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

## Properties

### ConnectionString

Gets the connection string of the database represented by this DbDataSource. The exact contents of the connection string depend on the specific data source for this connection.

    public override string ConnectionString { get; }

#### Property Value

string

  The connection string of the database represented by this DbDataSource. The exact contents of the connection string depend on the specific data source for this connection.

### Password

Manually sets the password to be used the next time a physical connection is opened. Consider using UsePeriodicPasswordProvider(Func<NpgsqlConnectionStringBuilder, CancellationToken, ValueTask<string>>?, TimeSpan, TimeSpan) instead.

    public string Password { set; }

#### Property Value

string

## Methods

### Create(NpgsqlConnectionStringBuilder)

Creates a new NpgsqlDataSource for the given `connectionStringBuilder`.

    public static NpgsqlDataSource Create(NpgsqlConnectionStringBuilder connectionStringBuilder)

#### Parameters

`connectionStringBuilder` NpgsqlConnectionStringBuilder

#### Returns

NpgsqlDataSource

### Create(string)

Creates a new NpgsqlDataSource for the given `connectionString`.

    public static NpgsqlDataSource Create(string connectionString)

#### Parameters

`connectionString` string

#### Returns

NpgsqlDataSource

### CreateBatch()

Creates a batch ready for use against this NpgsqlDataSource.

    public NpgsqlBatch CreateBatch()

#### Returns

NpgsqlBatch

### CreateCommand(string?)

Creates a command ready for use against this NpgsqlDataSource.

    public NpgsqlCommand CreateCommand(string? commandText = null)

#### Parameters

`commandText` string

  An optional SQL for the command.

#### Returns

NpgsqlCommand

### CreateConnection()

Returns a new, closed connection to the database represented by this DbDataSource.

    public NpgsqlConnection CreateConnection()

#### Returns

NpgsqlConnection

  A new, closed connection to the database represented by this DbDataSource.

### CreateDbBatch()

Returns a DbBatch that's ready for execution against the DbDataSource.

    protected override DbBatch CreateDbBatch()

#### Returns

DbBatch

  A DbBatch that's ready for execution against the DbDataSource.

### CreateDbCommand(string?)

Returns a DbCommand that's ready for execution against the DbDataSource.

    protected override DbCommand CreateDbCommand(string? commandText = null)

#### Parameters

`commandText` string

  The text command with which to initialize the DbCommand that this method returns.

#### Returns

DbCommand

  A DbCommand that's ready for execution against the DbDataSource.

### CreateDbConnection()

Returns a new, closed connection to the database represented by this DbDataSource.

    protected override DbConnection CreateDbConnection()

#### Returns

DbConnection

  A new, closed connection to the database represented by this DbDataSource.

### Dispose(bool)

Called by the Dispose() and Finalize() methods to release the managed and unmanaged resources used by the current instance of the DbDataSource class.

    protected override sealed void Dispose(bool disposing)

#### Parameters

`disposing` bool

  true to release both managed and unmanaged resources; false to release only unmanaged resources.

### DisposeAsyncBase()

Performs application-defined tasks associated with freeing, releasing, or resetting managed resources asynchronously.

    protected virtual ValueTask DisposeAsyncBase()

#### Returns

ValueTask

  A task that represents the asynchronous dispose operation.

### DisposeAsyncCore()

Performs application-defined tasks associated with freeing, releasing, or resetting managed resources asynchronously.

    protected override sealed ValueTask DisposeAsyncCore()

#### Returns

ValueTask

  A task that represents the asynchronous dispose operation.

### DisposeBase()

Called by the Dispose() and Finalize() methods to release the managed and unmanaged resources used by the current instance of the DbDataSource class.

    protected virtual void DisposeBase()

### OpenConnection()

Returns a new, open connection to the database represented by this DbDataSource.

    public NpgsqlConnection OpenConnection()

#### Returns

NpgsqlConnection

  A new, open connection to the database represented by this DbDataSource.

### OpenConnectionAsync(CancellationToken)

Asynchronously returns a new, open connection to the database represented by this DbDataSource.

    public ValueTask<NpgsqlConnection> OpenConnectionAsync(CancellationToken cancellationToken = default)

#### Parameters

`cancellationToken` CancellationToken

  A token to cancel the asynchronous operation.

#### Returns

ValueTask<NpgsqlConnection>

  A new, open connection to the database represented by this DbDataSource.

### OpenDbConnection()

Returns a new, open connection to the database represented by this DbDataSource.

    protected override DbConnection OpenDbConnection()

#### Returns

DbConnection

  A new, open connection to the database represented by this DbDataSource.

### OpenDbConnectionAsync(CancellationToken)

Asynchronously returns a new, open connection to the database represented by this DbDataSource.

    protected override ValueTask<DbConnection> OpenDbConnectionAsync(CancellationToken cancellationToken = default)

#### Parameters

`cancellationToken` CancellationToken

  A token to cancel the asynchronous operation.

#### Returns

ValueTask<DbConnection>

  A new, open connection to the database represented by this DbDataSource.