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
-
NpgsqlDataSource
- Implements
- Derived
- Inherited Members
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
Methods
Clear()
If the data source pools connections, clears any idle connections and flags any busy connections to be closed as soon as they're returned to the pool.
public abstract void Clear()
Create(NpgsqlConnectionStringBuilder)
Creates a new NpgsqlDataSource for the given connectionStringBuilder
.
public static NpgsqlDataSource Create(NpgsqlConnectionStringBuilder connectionStringBuilder)
Parameters
connectionStringBuilder
NpgsqlConnectionStringBuilder
Returns
Create(string)
Creates a new NpgsqlDataSource for the given connectionString
.
public static NpgsqlDataSource Create(string connectionString)
Parameters
connectionString
string
Returns
CreateBatch()
Creates a batch ready for use against this NpgsqlDataSource.
public NpgsqlBatch CreateBatch()
Returns
CreateCommand(string?)
Creates a command ready for use against this NpgsqlDataSource.
public NpgsqlCommand CreateCommand(string? commandText = null)
Parameters
commandText
stringAn optional SQL for the command.
Returns
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
stringThe 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
booltrue 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
CancellationTokenA 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
CancellationTokenA token to cancel the asynchronous operation.
Returns
- ValueTask<DbConnection>
A new, open connection to the database represented by this DbDataSource.