pub struct Config {Show 17 fields
pub host: String,
pub port: u16,
pub database: Option<String>,
pub credentials: Credentials,
pub tls: TlsConfig,
pub application_name: String,
pub connect_timeout: Duration,
pub command_timeout: Duration,
pub packet_size: u16,
pub strict_mode: bool,
pub trust_server_certificate: bool,
pub instance: Option<String>,
pub mars: bool,
pub encrypt: bool,
pub redirect: RedirectConfig,
pub retry: RetryPolicy,
pub timeouts: TimeoutConfig,
}Expand description
Configuration for connecting to SQL Server.
Fields§
§host: StringServer hostname or IP address.
port: u16Server port (default: 1433).
database: Option<String>Database name.
credentials: CredentialsAuthentication credentials.
tls: TlsConfigTLS configuration.
application_name: StringApplication name (shown in SQL Server management tools).
connect_timeout: DurationConnection timeout.
command_timeout: DurationCommand timeout.
packet_size: u16TDS packet size.
strict_mode: boolWhether to use TDS 8.0 strict mode.
trust_server_certificate: boolWhether to trust the server certificate.
instance: Option<String>Instance name (for named instances).
mars: boolWhether to enable MARS (Multiple Active Result Sets).
encrypt: boolWhether to require encryption (TLS). When true, the connection will use TLS even if the server doesn’t require it. When false, encryption is used only if the server requires it.
redirect: RedirectConfigRedirect handling configuration (for Azure SQL).
retry: RetryPolicyRetry policy for transient error handling.
timeouts: TimeoutConfigTimeout configuration for various connection phases.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_connection_string(conn_str: &str) -> Result<Self, Error>
pub fn from_connection_string(conn_str: &str) -> Result<Self, Error>
Parse a connection string into configuration.
Supports ADO.NET-style connection strings:
Server=localhost;Database=mydb;User Id=sa;Password=secret;Sourcepub fn credentials(self, credentials: Credentials) -> Self
pub fn credentials(self, credentials: Credentials) -> Self
Set the credentials.
Sourcepub fn application_name(self, name: impl Into<String>) -> Self
pub fn application_name(self, name: impl Into<String>) -> Self
Set the application name.
Sourcepub fn connect_timeout(self, timeout: Duration) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Set the connect timeout.
Sourcepub fn trust_server_certificate(self, trust: bool) -> Self
pub fn trust_server_certificate(self, trust: bool) -> Self
Set trust server certificate option.
Sourcepub fn strict_mode(self, enabled: bool) -> Self
pub fn strict_mode(self, enabled: bool) -> Self
Enable TDS 8.0 strict mode.
Sourcepub fn encrypt(self, enabled: bool) -> Self
pub fn encrypt(self, enabled: bool) -> Self
Enable or disable TLS encryption.
When true (default), the connection will use TLS encryption.
When false, encryption is used only if the server requires it.
Warning: Disabling encryption is insecure and should only be used for development/testing on trusted networks.
Sourcepub fn with_host(self, host: &str) -> Self
pub fn with_host(self, host: &str) -> Self
Create a new configuration with a different host (for routing).
Sourcepub fn with_port(self, port: u16) -> Self
pub fn with_port(self, port: u16) -> Self
Create a new configuration with a different port (for routing).
Sourcepub fn redirect(self, redirect: RedirectConfig) -> Self
pub fn redirect(self, redirect: RedirectConfig) -> Self
Set the redirect handling configuration.
Sourcepub fn max_redirects(self, max: u8) -> Self
pub fn max_redirects(self, max: u8) -> Self
Set the maximum number of redirect attempts.
Sourcepub fn retry(self, retry: RetryPolicy) -> Self
pub fn retry(self, retry: RetryPolicy) -> Self
Set the retry policy for transient error handling.
Sourcepub fn max_retries(self, max: u32) -> Self
pub fn max_retries(self, max: u32) -> Self
Set the maximum number of retry attempts.
Sourcepub fn timeouts(self, timeouts: TimeoutConfig) -> Self
pub fn timeouts(self, timeouts: TimeoutConfig) -> Self
Set the timeout configuration.