Class NpgsqlConnectionStringBuilder
- Namespace
- Npgsql
- Assembly
- Npgsql.dll
Provides a simple way to create and manage the contents of connection strings used by the NpgsqlConnection class.
public sealed class NpgsqlConnectionStringBuilder : DbConnectionStringBuilder, IDictionary, ICollection, ICustomTypeDescriptor, IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable
- Inheritance
-
NpgsqlConnectionStringBuilder
- Implements
- Inherited Members
Constructors
NpgsqlConnectionStringBuilder()
Initializes a new instance of the NpgsqlConnectionStringBuilder class.
public NpgsqlConnectionStringBuilder()
NpgsqlConnectionStringBuilder(bool)
Initializes a new instance of the NpgsqlConnectionStringBuilder class, optionally using ODBC rules for quoting values.
public NpgsqlConnectionStringBuilder(bool useOdbcRules)
Parameters
useOdbcRules
booltrue to use {} to delimit fields; false to use quotation marks.
NpgsqlConnectionStringBuilder(string)
Initializes a new instance of the NpgsqlConnectionStringBuilder class and sets its ConnectionString.
public NpgsqlConnectionStringBuilder(string connectionString)
Parameters
connectionString
string
Properties
ApplicationName
The optional application name parameter to be sent to the backend during connection initiation.
[NpgsqlConnectionStringProperty]
public string ApplicationName { get; set; }
Property Value
AutoPrepareMinUsages
The minimum number of usages an SQL statement is used before it's automatically prepared. Defaults to 5.
[NpgsqlConnectionStringProperty]
public int AutoPrepareMinUsages { get; set; }
Property Value
BackendTimeouts
Obsolete, see http://www.npgsql.org/doc/migration/3.1.html
[NpgsqlConnectionStringProperty]
[Obsolete("The BackendTimeouts parameter is no longer supported")]
public bool BackendTimeouts { get; set; }
Property Value
CheckCertificateRevocation
Whether to check the certificate revocation list during authentication. False by default.
[NpgsqlConnectionStringProperty]
public bool CheckCertificateRevocation { get; set; }
Property Value
ClientEncoding
Gets or sets the client_encoding parameter.
[NpgsqlConnectionStringProperty]
public string ClientEncoding { get; set; }
Property Value
CommandTimeout
The time to wait (in seconds) while trying to execute a command before terminating the attempt and generating an error. Defaults to 30 seconds.
[NpgsqlConnectionStringProperty]
public int CommandTimeout { get; set; }
Property Value
ConnectionIdleLifetime
The time to wait before closing idle connections in the pool if the count of all connections exceeds MinPoolSize.
[NpgsqlConnectionStringProperty]
public int ConnectionIdleLifetime { get; set; }
Property Value
- int
The time (in seconds) to wait. The default value is 300.
ConnectionLifeTime
Obsolete, see http://www.npgsql.org/doc/migration/3.1.html
[NpgsqlConnectionStringProperty]
[Obsolete("The ConnectionLifeTime parameter is no longer supported")]
public int ConnectionLifeTime { get; set; }
Property Value
ConnectionPruningInterval
How many seconds the pool waits before attempting to prune idle connections that are beyond idle lifetime (ConnectionIdleLifetime.
[NpgsqlConnectionStringProperty]
public int ConnectionPruningInterval { get; set; }
Property Value
- int
The interval (in seconds). The default value is 10.
ContinuousProcessing
Obsolete, see http://www.npgsql.org/doc/migration/3.1.html
[NpgsqlConnectionStringProperty]
[Obsolete("The ContinuousProcessing parameter is no longer supported.")]
public bool ContinuousProcessing { get; set; }
Property Value
ConvertInfinityDateTime
Makes MaxValue and MinValue timestamps and dates readable as infinity and negative infinity.
[NpgsqlConnectionStringProperty]
public bool ConvertInfinityDateTime { get; set; }
Property Value
Database
The PostgreSQL database to connect to.
[NpgsqlConnectionStringProperty(new string[] { "DB" })]
public string Database { get; set; }
Property Value
Encoding
Gets or sets the .NET encoding that will be used to encode/decode PostgreSQL string data.
[NpgsqlConnectionStringProperty]
public string Encoding { get; set; }
Property Value
Enlist
Whether to enlist in an ambient TransactionScope.
[NpgsqlConnectionStringProperty]
public bool Enlist { get; set; }
Property Value
EntityAdminDatabase
The database admin to specify when creating and dropping a database in Entity Framework. This is needed because Npgsql needs to connect to a database in order to send the create/drop database command. If not specified, defaults to "template1". Check NpgsqlServices.UsingPostgresDBConnection for more information.
[NpgsqlConnectionStringProperty]
public string EntityAdminDatabase { get; set; }
Property Value
EntityTemplateDatabase
The database template to specify when creating a database in Entity Framework. If not specified, PostgreSQL defaults to "template1".
[NpgsqlConnectionStringProperty]
public string EntityTemplateDatabase { get; set; }
Property Value
Remarks
Host
The hostname or IP address of the PostgreSQL server to connect to.
[NpgsqlConnectionStringProperty(new string[] { "Server" })]
public string Host { get; set; }
Property Value
IncludeErrorDetails
When enabled, PostgreSQL error details are included on Detail and Detail. These can contain sensitive data.
[NpgsqlConnectionStringProperty]
public bool IncludeErrorDetails { get; set; }
Property Value
IncludeRealm
The Kerberos realm to be used for authentication.
[NpgsqlConnectionStringProperty]
public bool IncludeRealm { get; set; }
Property Value
IntegratedSecurity
Whether to use Windows integrated security to log in.
[NpgsqlConnectionStringProperty]
public bool IntegratedSecurity { get; set; }
Property Value
InternalCommandTimeout
The time to wait (in seconds) while trying to execute a an internal command before terminating the attempt and generating an error.
[NpgsqlConnectionStringProperty]
public int InternalCommandTimeout { get; set; }
Property Value
this[string]
Gets or sets the value associated with the specified key.
public override object this[string keyword] { get; set; }
Parameters
keyword
stringThe key of the item to get or set.
Property Value
- object
The value associated with the specified key.
KeepAlive
The number of seconds of connection inactivity before Npgsql sends a keepalive query. Set to 0 (the default) to disable.
[NpgsqlConnectionStringProperty]
public int KeepAlive { get; set; }
Property Value
KerberosServiceName
The Kerberos service name to be used for authentication.
[NpgsqlConnectionStringProperty(new string[] { "Krbsrvname" })]
public string KerberosServiceName { get; set; }
Property Value
Keys
Gets an ICollection{string} containing the keys of the NpgsqlConnectionStringBuilder.
public ICollection<string> Keys { get; }
Property Value
LoadTableComposites
Load table composite type definitions, and not just free-standing composite types.
[NpgsqlConnectionStringProperty]
public bool LoadTableComposites { get; set; }
Property Value
LogParameters
When enabled, parameter values are logged when commands are executed. Defaults to false.
[NpgsqlConnectionStringProperty]
public bool LogParameters { get; set; }
Property Value
MaxAutoPrepare
The maximum number SQL statements that can be automatically prepared at any given point. Beyond this number the least-recently-used statement will be recycled. Zero (the default) disables automatic preparation.
[NpgsqlConnectionStringProperty]
public int MaxAutoPrepare { get; set; }
Property Value
MaxPoolSize
The maximum connection pool size.
[NpgsqlConnectionStringProperty]
public int MaxPoolSize { get; set; }
Property Value
MinPoolSize
The minimum connection pool size.
[NpgsqlConnectionStringProperty]
public int MinPoolSize { get; set; }
Property Value
NoResetOnClose
If set to true, a pool connection's state won't be reset when it is closed (improves performance). Do not specify this unless you know what you're doing.
[NpgsqlConnectionStringProperty]
public bool NoResetOnClose { get; set; }
Property Value
Passfile
Path to a PostgreSQL password file (PGPASSFILE), from which the password would be taken.
[NpgsqlConnectionStringProperty]
public string Passfile { get; set; }
Property Value
Password
The password to connect with. Not required if using IntegratedSecurity.
[NpgsqlConnectionStringProperty(new string[] { "PSW", "PWD" })]
public string Password { get; set; }
Property Value
PersistSecurityInfo
Gets or sets a Boolean value that indicates if security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state.
[NpgsqlConnectionStringProperty]
public bool PersistSecurityInfo { get; set; }
Property Value
Pooling
Whether connection pooling should be used.
[NpgsqlConnectionStringProperty]
public bool Pooling { get; set; }
Property Value
Port
The TCP/IP port of the PostgreSQL server.
[NpgsqlConnectionStringProperty]
public int Port { get; set; }
Property Value
PreloadReader
Obsolete, see http://www.npgsql.org/doc/migration/3.0.html
[NpgsqlConnectionStringProperty]
[Obsolete("The PreloadReader parameter is no longer supported")]
public bool PreloadReader { get; set; }
Property Value
ReadBufferSize
Determines the size of the internal buffer Npgsql uses when reading. Increasing may improve performance if transferring large values from the database.
[NpgsqlConnectionStringProperty]
public int ReadBufferSize { get; set; }
Property Value
SearchPath
Gets or sets the schema search path.
[NpgsqlConnectionStringProperty]
public string SearchPath { get; set; }
Property Value
ServerCompatibilityMode
A compatibility mode for special PostgreSQL server types.
[NpgsqlConnectionStringProperty]
public ServerCompatibilityMode ServerCompatibilityMode { get; set; }
Property Value
SocketReceiveBufferSize
Determines the size of socket read buffer.
[NpgsqlConnectionStringProperty]
public int SocketReceiveBufferSize { get; set; }
Property Value
SocketSendBufferSize
Determines the size of socket send buffer.
[NpgsqlConnectionStringProperty]
public int SocketSendBufferSize { get; set; }
Property Value
SslMode
Controls whether SSL is required, disabled or preferred, depending on server support.
[NpgsqlConnectionStringProperty]
public SslMode SslMode { get; set; }
Property Value
TcpKeepAlive
Whether to use TCP keepalive with system defaults if overrides isn't specified.
[NpgsqlConnectionStringProperty]
public bool TcpKeepAlive { get; set; }
Property Value
TcpKeepAliveInterval
The interval, in milliseconds, between when successive keep-alive packets are sent if no acknowledgement is received. Defaults to the value of TcpKeepAliveTime. TcpKeepAliveTime must be non-zero as well. Supported only on Windows.
[NpgsqlConnectionStringProperty]
public int TcpKeepAliveInterval { get; set; }
Property Value
TcpKeepAliveTime
The number of seconds of connection inactivity before a TCP keepalive query is sent. Use of this option is discouraged, use KeepAlive instead if possible. Set to 0 (the default) to disable. Supported only on Windows.
[NpgsqlConnectionStringProperty]
public int TcpKeepAliveTime { get; set; }
Property Value
Timeout
The time to wait (in seconds) while trying to establish a connection before terminating the attempt and generating an error. Defaults to 15 seconds.
[NpgsqlConnectionStringProperty]
public int Timeout { get; set; }
Property Value
Timezone
Gets or sets the PostgreSQL session timezone, in Olson/IANA database format.
[NpgsqlConnectionStringProperty]
public string Timezone { get; set; }
Property Value
TrustServerCertificate
Whether to trust the server certificate without validating it.
[NpgsqlConnectionStringProperty]
public bool TrustServerCertificate { get; set; }
Property Value
UseExtendedTypes
Obsolete, see http://www.npgsql.org/doc/migration/3.0.html
[NpgsqlConnectionStringProperty]
[Obsolete("The UseExtendedTypes parameter is no longer supported")]
public bool UseExtendedTypes { get; set; }
Property Value
UsePerfCounters
Writes connection performance information to performance counters.
[NpgsqlConnectionStringProperty]
public bool UsePerfCounters { get; set; }
Property Value
UseSslStream
Npgsql uses its own internal implementation of TLS/SSL. Turn this on to use .NET SslStream instead.
[NpgsqlConnectionStringProperty]
public bool UseSslStream { get; set; }
Property Value
Username
The username to connect with. Not required if using IntegratedSecurity.
[NpgsqlConnectionStringProperty(new string[] { "User Name", "UserId", "User Id", "UID" })]
public string Username { get; set; }
Property Value
Values
Gets an ICollection{string} containing the values in the NpgsqlConnectionStringBuilder.
public ICollection<object> Values { get; }
Property Value
WriteBufferSize
Determines the size of the internal buffer Npgsql uses when writing. Increasing may improve performance if transferring large values to the database.
[NpgsqlConnectionStringProperty]
public int WriteBufferSize { get; set; }
Property Value
Methods
Add(KeyValuePair<string, object>)
Adds an item to the NpgsqlConnectionStringBuilder.
public void Add(KeyValuePair<string, object> item)
Parameters
item
KeyValuePair<string, object>The key-value pair to be added.
Clear()
Clears the contents of the NpgsqlConnectionStringBuilder instance.
public override void Clear()
Contains(KeyValuePair<string, object>)
Determines whether the NpgsqlConnectionStringBuilder contains a specific key-value pair.
public bool Contains(KeyValuePair<string, object> item)
Parameters
item
KeyValuePair<string, object>The itemto locate in the NpgsqlConnectionStringBuilder.
Returns
- bool
true if the NpgsqlConnectionStringBuilder contains the entry; otherwise false.
ContainsKey(string)
Determines whether the NpgsqlConnectionStringBuilder contains a specific key.
public override bool ContainsKey(string keyword)
Parameters
keyword
stringThe key to locate in the NpgsqlConnectionStringBuilder.
Returns
- bool
true if the NpgsqlConnectionStringBuilder contains an entry with the specified key; otherwise false.
CopyTo(KeyValuePair<string, object>[], int)
Copies the elements of the NpgsqlConnectionStringBuilder to an Array, starting at a particular Array index.
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
Parameters
array
KeyValuePair<string, object>[]The one-dimensional Array that is the destination of the elements copied from NpgsqlConnectionStringBuilder. The Array must have zero-based indexing.
arrayIndex
intThe zero-based index in array at which copying begins.
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
obj
object
Returns
GetEnumerator()
Returns an enumerator that iterates through the NpgsqlConnectionStringBuilder.
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
Returns
GetHashCode()
Hash function.
public override int GetHashCode()
Returns
GetProperties(Hashtable)
protected override void GetProperties(Hashtable propertyDescriptors)
Parameters
propertyDescriptors
Hashtable
Remove(KeyValuePair<string, object>)
Removes the entry from the DbConnectionStringBuilder instance.
public bool Remove(KeyValuePair<string, object> item)
Parameters
item
KeyValuePair<string, object>The key/value pair to be removed from the connection string in this DbConnectionStringBuilder.
Returns
- bool
true if the key existed within the connection string and was removed; false if the key did not exist.
Remove(string)
Removes the entry with the specified key from the DbConnectionStringBuilder instance.
public override bool Remove(string keyword)
Parameters
keyword
stringThe key of the key/value pair to be removed from the connection string in this DbConnectionStringBuilder.
Returns
- bool
true if the key existed within the connection string and was removed; false if the key did not exist.
TryGetValue(string, out object)
Retrieves a value corresponding to the supplied key from this NpgsqlConnectionStringBuilder.
public override bool TryGetValue(string keyword, out object value)
Parameters
Returns
- bool
true if keyword was found within the connection string, false otherwise.