Class NpgsqlConnection
This class represents a connection to a PostgreSQL server.
Implements
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlConnection : DbConnection, ICloneable, IComponent
Constructors
| Improve this Doc View SourceNpgsqlConnection()
Initializes a new instance of the NpgsqlConnection class.
Declaration
public NpgsqlConnection()
NpgsqlConnection(string?)
Initializes a new instance of NpgsqlConnection with the given connection string.
Declaration
public NpgsqlConnection(string? connectionString)
Parameters
Type | Name | Description |
---|---|---|
string? | connectionString | The connection used to open the PostgreSQL database. |
Fields
| Improve this Doc View SourceDefaultPort
The default TCP/IP port for PostgreSQL.
Declaration
public const int DefaultPort
Field Value
Type | Description |
---|---|
int |
Properties
| Improve this Doc View SourceCommandTimeout
Gets the time (in seconds) to wait while trying to execute a command before terminating the attempt and generating an error.
Declaration
public int CommandTimeout { get; }
Property Value
Type | Description |
---|---|
int | The time (in seconds) to wait for a command to complete. The default value is 20 seconds. |
ConnectionString
Gets or sets the string used to connect to a PostgreSQL database. See the manual for details.
Declaration
public override string ConnectionString { get; set; }
Property Value
Type | Description |
---|---|
string | The connection string that includes the server name, the database name, and other parameters needed to establish the initial connection. The default value is an empty string. |
ConnectionTimeout
Gets the time (in seconds) to wait while trying to establish a connection before terminating the attempt and generating an error.
Declaration
public override int ConnectionTimeout { get; }
Property Value
Type | Description |
---|---|
int | The time (in seconds) to wait for a connection to open. The default value is 15 seconds. |
Database
Gets the name of the current database or the database to be used after a connection is opened.
Declaration
public override string Database { get; }
Property Value
Type | Description |
---|---|
string | The name of the current database or the name of the database to be used after a connection is opened. The default value is the empty string. |
DataSource
Gets the string identifying the database server (host and port)
Declaration
public override string DataSource { get; }
Property Value
Type | Description |
---|---|
string | The name of the database server (host and port). If the connection uses a Unix-domain socket, the path to that socket is returned. The default value is the empty string. |
DbProviderFactory
DB provider factory.
Declaration
protected override DbProviderFactory DbProviderFactory { get; }
Property Value
Type | Description |
---|---|
DbProviderFactory |
FullState
Gets the current state of the connection.
Declaration
public ConnectionState FullState { get; }
Property Value
Type | Description |
---|---|
ConnectionState | A bitwise combination of the |
GlobalTypeMapper
The global type mapper, which contains defaults used by all new connections. Modify mappings on this mapper to affect your entire application.
Declaration
public static INpgsqlTypeMapper GlobalTypeMapper { get; }
Property Value
Type | Description |
---|---|
INpgsqlTypeMapper |
HasIntegerDateTimes
Reports whether the backend uses the newer integer timestamp representation. Note that the old floating point representation is not supported. Meant for use by type plugins (e.g. NodaTime)
Declaration
public bool HasIntegerDateTimes { get; }
Property Value
Type | Description |
---|---|
bool |
Host
Backend server host name.
Declaration
public string? Host { get; }
Property Value
Type | Description |
---|---|
string? |
IntegratedSecurity
Whether to use Windows integrated security to log in.
Declaration
public bool IntegratedSecurity { get; }
Property Value
Type | Description |
---|---|
bool |
Port
Backend server port.
Declaration
public int Port { get; }
Property Value
Type | Description |
---|---|
int |
PostgresParameters
Holds all PostgreSQL parameters received for this connection. Is updated if the values change (e.g. as a result of a SET command).
Declaration
public IReadOnlyDictionary<string, string> PostgresParameters { get; }
Property Value
Type | Description |
---|---|
IReadOnlyDictionary<, ><string, string> |
PostgreSqlVersion
The version of the PostgreSQL server we're connected to.
This can only be called when the connection is open.
In case of a development or pre-release version this field will contain the version of the next version to be released from this branch.
Declaration
public Version PostgreSqlVersion { get; }
Property Value
Type | Description |
---|---|
Version |
ProcessID
Process id of backend server. This can only be called when there is an active connection.
Declaration
public int ProcessID { get; }
Property Value
Type | Description |
---|---|
int |
ProvideClientCertificatesCallback
Selects the local Secure Sockets Layer (SSL) certificate used for authentication.
Declaration
public ProvideClientCertificatesCallback? ProvideClientCertificatesCallback { get; set; }
Property Value
Type | Description |
---|---|
ProvideClientCertificatesCallback |
Remarks
| Improve this Doc View SourceProvidePasswordCallback
Gets or sets the delegate used to generate a password for new database connections.
Declaration
public ProvidePasswordCallback? ProvidePasswordCallback { get; set; }
Property Value
Type | Description |
---|---|
ProvidePasswordCallback |
Remarks
This delegate is executed when a new database connection is opened that requires a password.
The Password and Passfile connection string properties have precedence over this delegate: it will not be executed if a password is specified, or if the specified or default Passfile contains a valid entry.
Due to connection pooling this delegate is only executed when a new physical connection is opened, not when reusing a connection that was previously opened from the pool.
ServerVersion
The PostgreSQL server version as returned by the server_version option.
Declaration
public override string ServerVersion { get; }
Property Value
Type | Description |
---|---|
string |
State
Gets whether the current state of the connection is Open or Closed
Declaration
public override ConnectionState State { get; }
Property Value
Type | Description |
---|---|
ConnectionState | ConnectionState.Open, ConnectionState.Closed or ConnectionState.Connecting |
Timezone
The connection's timezone as reported by PostgreSQL, in the IANA/Olson database format.
Declaration
public string Timezone { get; }
Property Value
Type | Description |
---|---|
string |
TypeMapper
Connection-level type mapping is no longer supported. See the 7.0 release notes for configuring type mapping on NpgsqlDataSource.
Declaration
public INpgsqlTypeMapper TypeMapper { get; }
Property Value
Type | Description |
---|---|
INpgsqlTypeMapper |
UserCertificateValidationCallback
When using SSL/TLS, this is a callback that allows customizing how the PostgreSQL-provided certificate is verified. This is an advanced API, consider using VerifyFull or VerifyCA instead.
Declaration
public RemoteCertificateValidationCallback? UserCertificateValidationCallback { get; set; }
Property Value
Type | Description |
---|---|
RemoteCertificateValidationCallback? |
Remarks
Cannot be used in conjunction with Disable, VerifyCA and VerifyFull.
UserName
User name.
Declaration
public string? UserName { get; }
Property Value
Type | Description |
---|---|
string? |
Methods
| Improve this Doc View SourceBeginBinaryExport(string)
Begins a binary COPY TO STDOUT operation, a high-performance data export mechanism from a PostgreSQL table.
Declaration
public NpgsqlBinaryExporter BeginBinaryExport(string copyToCommand)
Parameters
Type | Name | Description |
---|---|---|
string | copyToCommand | A COPY TO STDOUT SQL command |
Returns
Type | Description |
---|---|
NpgsqlBinaryExporter | A NpgsqlBinaryExporter which can be used to read rows and columns |
Remarks
| Improve this Doc View SourceBeginBinaryExportAsync(string, CancellationToken)
Begins a binary COPY TO STDOUT operation, a high-performance data export mechanism from a PostgreSQL table.
Declaration
public Task<NpgsqlBinaryExporter> BeginBinaryExportAsync(string copyToCommand, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | copyToCommand | A COPY TO STDOUT SQL command |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task<><NpgsqlBinaryExporter> | A NpgsqlBinaryExporter which can be used to read rows and columns |
Remarks
| Improve this Doc View SourceBeginBinaryImport(string)
Begins a binary COPY FROM STDIN operation, a high-performance data import mechanism to a PostgreSQL table.
Declaration
public NpgsqlBinaryImporter BeginBinaryImport(string copyFromCommand)
Parameters
Type | Name | Description |
---|---|---|
string | copyFromCommand | A COPY FROM STDIN SQL command |
Returns
Type | Description |
---|---|
NpgsqlBinaryImporter | A NpgsqlBinaryImporter which can be used to write rows and columns |
Remarks
| Improve this Doc View SourceBeginBinaryImportAsync(string, CancellationToken)
Begins a binary COPY FROM STDIN operation, a high-performance data import mechanism to a PostgreSQL table.
Declaration
public Task<NpgsqlBinaryImporter> BeginBinaryImportAsync(string copyFromCommand, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | copyFromCommand | A COPY FROM STDIN SQL command |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task<><NpgsqlBinaryImporter> | A NpgsqlBinaryImporter which can be used to write rows and columns |
Remarks
| Improve this Doc View SourceBeginDbTransaction(IsolationLevel)
Begins a database transaction with the specified isolation level.
Declaration
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
Parameters
Type | Name | Description |
---|---|---|
IsolationLevel | isolationLevel | The isolation level under which the transaction should run. |
Returns
Type | Description |
---|---|
DbTransaction | A |
Remarks
Nested transactions are not supported.
BeginDbTransactionAsync(IsolationLevel, CancellationToken)
Asynchronously begins a database transaction.
Declaration
protected override ValueTask<DbTransaction> BeginDbTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
IsolationLevel | isolationLevel | The isolation level under which the transaction should run. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
ValueTask<><DbTransaction> | A task whose |
Remarks
Nested transactions are not supported.
BeginRawBinaryCopy(string)
Begins a raw binary COPY operation (TO STDOUT or FROM STDIN), a high-performance data export/import mechanism to a PostgreSQL table. Note that unlike the other COPY API methods, BeginRawBinaryCopy(string) doesn't implement any encoding/decoding and is unsuitable for structured import/export operation. It is useful mainly for exporting a table as an opaque blob, for the purpose of importing it back later.
Declaration
public NpgsqlRawCopyStream BeginRawBinaryCopy(string copyCommand)
Parameters
Type | Name | Description |
---|---|---|
string | copyCommand | A COPY TO STDOUT or COPY FROM STDIN SQL command |
Returns
Type | Description |
---|---|
NpgsqlRawCopyStream | A NpgsqlRawCopyStream that can be used to read or write raw binary data. |
Remarks
| Improve this Doc View SourceBeginRawBinaryCopyAsync(string, CancellationToken)
Begins a raw binary COPY operation (TO STDOUT or FROM STDIN), a high-performance data export/import mechanism to a PostgreSQL table. Note that unlike the other COPY API methods, BeginRawBinaryCopyAsync(string, CancellationToken) doesn't implement any encoding/decoding and is unsuitable for structured import/export operation. It is useful mainly for exporting a table as an opaque blob, for the purpose of importing it back later.
Declaration
public Task<NpgsqlRawCopyStream> BeginRawBinaryCopyAsync(string copyCommand, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | copyCommand | A COPY TO STDOUT or COPY FROM STDIN SQL command |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task<><NpgsqlRawCopyStream> | A NpgsqlRawCopyStream that can be used to read or write raw binary data. |
Remarks
| Improve this Doc View SourceBeginTextExport(string)
Begins a textual COPY TO STDOUT operation, a data export mechanism from a PostgreSQL table.
It is the user's responsibility to parse the textual input according to the format specified
in copyToCommand
.
Declaration
public TextReader BeginTextExport(string copyToCommand)
Parameters
Type | Name | Description |
---|---|---|
string | copyToCommand | A COPY TO STDOUT SQL command |
Returns
Type | Description |
---|---|
TextReader | A TextReader that can be used to read textual data. |
Remarks
| Improve this Doc View SourceBeginTextExportAsync(string, CancellationToken)
Begins a textual COPY TO STDOUT operation, a data export mechanism from a PostgreSQL table.
It is the user's responsibility to parse the textual input according to the format specified
in copyToCommand
.
Declaration
public Task<TextReader> BeginTextExportAsync(string copyToCommand, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | copyToCommand | A COPY TO STDOUT SQL command |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task<><TextReader> | A TextReader that can be used to read textual data. |
Remarks
| Improve this Doc View SourceBeginTextImport(string)
Begins a textual COPY FROM STDIN operation, a data import mechanism to a PostgreSQL table.
It is the user's responsibility to send the textual input according to the format specified
in copyFromCommand
.
Declaration
public TextWriter BeginTextImport(string copyFromCommand)
Parameters
Type | Name | Description |
---|---|---|
string | copyFromCommand | A COPY FROM STDIN SQL command |
Returns
Type | Description |
---|---|
TextWriter | A TextWriter that can be used to send textual data. |
Remarks
| Improve this Doc View SourceBeginTextImportAsync(string, CancellationToken)
Begins a textual COPY FROM STDIN operation, a data import mechanism to a PostgreSQL table.
It is the user's responsibility to send the textual input according to the format specified
in copyFromCommand
.
Declaration
public Task<TextWriter> BeginTextImportAsync(string copyFromCommand, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | copyFromCommand | A COPY FROM STDIN SQL command |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task<><TextWriter> | A TextWriter that can be used to send textual data. |
Remarks
| Improve this Doc View SourceBeginTransaction()
Begins a database transaction.
Declaration
public NpgsqlTransaction BeginTransaction()
Returns
Type | Description |
---|---|
NpgsqlTransaction | A NpgsqlTransaction object representing the new transaction. |
Remarks
Nested transactions are not supported.
Transactions created by this method will have the
BeginTransaction(IsolationLevel)
Begins a database transaction with the specified isolation level.
Declaration
public NpgsqlTransaction BeginTransaction(IsolationLevel level)
Parameters
Type | Name | Description |
---|---|---|
IsolationLevel | level | The isolation level under which the transaction should run. |
Returns
Type | Description |
---|---|
NpgsqlTransaction | A NpgsqlTransaction object representing the new transaction. |
Remarks
Nested transactions are not supported.
BeginTransactionAsync(CancellationToken)
Asynchronously begins a database transaction.
Declaration
public ValueTask<NpgsqlTransaction> BeginTransactionAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
ValueTask<><NpgsqlTransaction> | A task whose Result property is an object representing the new transaction. |
Remarks
Nested transactions are not supported.
Transactions created by this method will have the
BeginTransactionAsync(IsolationLevel, CancellationToken)
Asynchronously begins a database transaction.
Declaration
public ValueTask<NpgsqlTransaction> BeginTransactionAsync(IsolationLevel level, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
IsolationLevel | level | The isolation level under which the transaction should run. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
ValueTask<><NpgsqlTransaction> | A task whose |
Remarks
Nested transactions are not supported.
ChangeDatabase(string)
This method changes the current database by disconnecting from the actual database and connecting to the specified.
Declaration
public override void ChangeDatabase(string dbName)
Parameters
Type | Name | Description |
---|---|---|
string | dbName | The name of the database to use in place of the current database. |
ClearAllPools()
Clear all connection pools. All idle physical connections in all pools are immediately closed, and any busy connections which were opened before ClearAllPools() was called will be closed when returned to their pool.
Declaration
public static void ClearAllPools()
ClearPool(NpgsqlConnection)
Clears the connection pool. All idle physical connections in the pool of the given connection are immediately closed, and any busy connections which were opened before ClearPool(NpgsqlConnection) was called will be closed when returned to the pool.
Declaration
public static void ClearPool(NpgsqlConnection connection)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlConnection | connection |
CloneWith(string)
Clones this connection, replacing its connection string with the given one. This allows creating a new connection with the same security information (password, SSL callbacks) while changing other connection parameters (e.g. database or pooling)
Declaration
public NpgsqlConnection CloneWith(string connectionString)
Parameters
Type | Name | Description |
---|---|---|
string | connectionString |
Returns
Type | Description |
---|---|
NpgsqlConnection |
Close()
Releases the connection. If the connection is pooled, it will be returned to the pool and made available for re-use. If it is non-pooled, the physical connection will be closed.
Declaration
public override void Close()
CloseAsync()
Releases the connection. If the connection is pooled, it will be returned to the pool and made available for re-use. If it is non-pooled, the physical connection will be closed.
Declaration
public override Task CloseAsync()
Returns
Type | Description |
---|---|
Task |
CreateBatch()
Creates and returns a NpgsqlBatch object associated with the NpgsqlConnection.
Declaration
public NpgsqlBatch CreateBatch()
Returns
Type | Description |
---|---|
NpgsqlBatch | A NpgsqlBatch object. |
CreateCommand()
Creates and returns a NpgsqlCommand object associated with the NpgsqlConnection.
Declaration
public NpgsqlCommand CreateCommand()
Returns
Type | Description |
---|---|
NpgsqlCommand | A NpgsqlCommand object. |
CreateDbCommand()
Creates and returns a
Declaration
protected override DbCommand CreateDbCommand()
Returns
Type | Description |
---|---|
DbCommand | A |
Dispose(bool)
Releases all resources used by the NpgsqlConnection.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | true when called from Dispose(bool); false when being called from the finalizer. |
DisposeAsync()
Releases all resources used by the NpgsqlConnection.
Declaration
public override ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask |
EnlistTransaction(Transaction?)
Enlist transaction.
Declaration
public override void EnlistTransaction(Transaction? transaction)
Parameters
Type | Name | Description |
---|---|---|
Transaction? | transaction |
GetSchema()
Returns the supported collections
Declaration
public override DataTable GetSchema()
Returns
Type | Description |
---|---|
DataTable |
GetSchema(string?, string?[]?)
Returns the schema collection specified by the collection name filtered by the restrictions.
Declaration
public override DataTable GetSchema(string? collectionName, string?[]? restrictions)
Parameters
Type | Name | Description |
---|---|---|
string? | collectionName | The collection name. |
string?[] | restrictions | The restriction values to filter the results. A description of the restrictions is contained in the Restrictions collection. |
Returns
Type | Description |
---|---|
DataTable | The collection specified. |
GetSchema(string?)
Returns the schema collection specified by the collection name.
Declaration
public override DataTable GetSchema(string? collectionName)
Parameters
Type | Name | Description |
---|---|---|
string? | collectionName | The collection name. |
Returns
Type | Description |
---|---|
DataTable | The collection specified. |
GetSchemaAsync(CancellationToken)
Asynchronously returns the supported collections.
Declaration
public Task<DataTable> GetSchemaAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task<><DataTable> | The collection specified. |
GetSchemaAsync(string, CancellationToken)
Asynchronously returns the schema collection specified by the collection name.
Declaration
public Task<DataTable> GetSchemaAsync(string collectionName, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | collectionName | The collection name. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task<><DataTable> | The collection specified. |
GetSchemaAsync(string, string?[]?, CancellationToken)
Asynchronously returns the schema collection specified by the collection name filtered by the restrictions.
Declaration
public Task<DataTable> GetSchemaAsync(string collectionName, string?[]? restrictions, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
string | collectionName | The collection name. |
string?[] | restrictions | The restriction values to filter the results. A description of the restrictions is contained in the Restrictions collection. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task<><DataTable> | The collection specified. |
Open()
Opens a database connection with the property settings specified by the ConnectionString.
Declaration
public override void Open()
OpenAsync(CancellationToken)
This is the asynchronous version of Open().
Declaration
public override Task OpenAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task | A task representing the asynchronous operation. |
Remarks
Do not invoke other methods and properties of the NpgsqlConnection object until the returned Task is complete.
ReloadTypes()
Flushes the type cache for this connection's connection string and reloads the types for this connection only. Type changes will appear for other connections only after they are re-opened from the pool.
Declaration
public void ReloadTypes()
ReloadTypesAsync()
Flushes the type cache for this connection's connection string and reloads the types for this connection only. Type changes will appear for other connections only after they are re-opened from the pool.
Declaration
public Task ReloadTypesAsync()
Returns
Type | Description |
---|---|
Task |
UnprepareAll()
Unprepares all prepared statements on this connection.
Declaration
public void UnprepareAll()
Wait()
Waits until an asynchronous PostgreSQL messages (e.g. a notification) arrives, and exits immediately. The asynchronous message is delivered via the normal events (Notification, Notice).
Declaration
public void Wait()
Wait(int)
Waits until an asynchronous PostgreSQL messages (e.g. a notification) arrives, and exits immediately. The asynchronous message is delivered via the normal events (Notification, Notice).
Declaration
public bool Wait(int timeout)
Parameters
Type | Name | Description |
---|---|---|
int | timeout | The time-out value, in milliseconds, passed to |
Returns
Type | Description |
---|---|
bool | true if an asynchronous message was received, false if timed out. |
Wait(TimeSpan)
Waits until an asynchronous PostgreSQL messages (e.g. a notification) arrives, and exits immediately. The asynchronous message is delivered via the normal events (Notification, Notice).
Declaration
public bool Wait(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The time-out value is passed to |
Returns
Type | Description |
---|---|
bool | true if an asynchronous message was received, false if timed out. |
WaitAsync(CancellationToken)
Waits asynchronously until an asynchronous PostgreSQL messages (e.g. a notification) arrives, and exits immediately. The asynchronous message is delivered via the normal events (Notification, Notice).
Declaration
public Task WaitAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task |
WaitAsync(int, CancellationToken)
Waits asynchronously until an asynchronous PostgreSQL messages (e.g. a notification) arrives, and exits immediately. The asynchronous message is delivered via the normal events (Notification, Notice).
Declaration
public Task<bool> WaitAsync(int timeout, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
int | timeout | The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task<><bool> | true if an asynchronous message was received, false if timed out. |
WaitAsync(TimeSpan, CancellationToken)
Waits asynchronously until an asynchronous PostgreSQL messages (e.g. a notification) arrives, and exits immediately. The asynchronous message is delivered via the normal events (Notification, Notice).
Declaration
public Task<bool> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The time-out value as |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is |
Returns
Type | Description |
---|---|
Task<><bool> | true if an asynchronous message was received, false if timed out. |
Events
| Improve this Doc View SourceDisposed
This event is unsupported by Npgsql. Use
Declaration
public event EventHandler? Disposed
Event Type
Type | Description |
---|---|
EventHandler? |
Notice
Fires when PostgreSQL notices are received from PostgreSQL.
Declaration
public event NoticeEventHandler? Notice
Event Type
Type | Description |
---|---|
NoticeEventHandler |
Remarks
PostgreSQL notices are non-critical messages generated by PostgreSQL, either as a result of a user query (e.g. as a warning or informational notice), or due to outside activity (e.g. if the database administrator initiates a "fast" database shutdown).
Note that notices are very different from notifications (see the Notification event).
Notification
Fires when PostgreSQL notifications are received from PostgreSQL.
Declaration
public event NotificationEventHandler? Notification
Event Type
Type | Description |
---|---|
NotificationEventHandler |
Remarks
PostgreSQL notifications are sent when your connection has registered for notifications on a specific channel via the LISTEN command. NOTIFY can be used to generate such notifications, allowing for an inter-connection communication channel.
Note that notifications are very different from notices (see the Notice event).