tiberius

Struct Config

Source
pub struct Config { /* private fields */ }
Expand description

The Config struct contains all configuration information required for connecting to the database with a Client. It also provides the server address when connecting to a TcpStream via the get_addr method.

When using an ADO.NET connection string, it can be constructed using the from_ado_string function.

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Create a new Config with the default settings.

Source

pub fn host(&mut self, host: impl ToString)

A host or ip address to connect to.

  • Defaults to localhost.
Source

pub fn port(&mut self, port: u16)

The server port.

  • Defaults to 1433.
Source

pub fn database(&mut self, database: impl ToString)

The database to connect to.

  • Defaults to master.
Source

pub fn instance_name(&mut self, name: impl ToString)

The instance name as defined in the SQL Browser. Only available on Windows platforms.

If specified, the port is replaced with the value returned from the browser.

  • Defaults to no name specified.
Source

pub fn application_name(&mut self, name: impl ToString)

Sets the application name to the connection, queryable with the APP_NAME() command.

  • Defaults to no name specified.
Source

pub fn encryption(&mut self, encryption: EncryptionLevel)

Set the preferred encryption level.

  • With tls feature, defaults to Required.
  • Without tls feature, defaults to NotSupported.
Source

pub fn trust_cert(&mut self)

If set, the server certificate will not be validated and it is accepted as-is.

On production setting, the certificate should be added to the local key storage (or use trust_cert_ca instead), using this setting is potentially dangerous.

§Panics

Will panic in case trust_cert_ca was called before.

  • Defaults to default, meaning server certificate is validated against system-truststore.
Source

pub fn trust_cert_ca(&mut self, path: impl ToString)

If set, the server certificate will be validated against the given CA certificate in in addition to the system-truststore. Useful when using self-signed certificates on the server without having to disable the trust-chain.

§Panics

Will panic in case trust_cert was called before.

  • Defaults to validating the server certificate is validated against system’s certificate storage.
Source

pub fn authentication(&mut self, auth: AuthMethod)

Sets the authentication method.

  • Defaults to None.
Source

pub fn get_addr(&self) -> String

Get the host address including port

Source

pub fn from_ado_string(s: &str) -> Result<Self>

Creates a new Config from an ADO.NET connection string.

§Supported parameters

All parameter keys are handled case-insensitive.

ParameterAllowed valuesDescription
server<string>The name or network address of the instance of SQL Server to which to connect. The port number can be specified after the server name. The correct form of this parameter is either tcp:host,port or tcp:host\\instance
IntegratedSecuritytrue,false,yes,noToggle between Windows/Kerberos authentication and SQL authentication.
uid,username,user,user id<string>The SQL Server login account.
password,pwd<string>The password for the SQL Server account logging on.
database<string>The name of the database.
TrustServerCertificatetrue,false,yes,noSpecifies whether the driver trusts the server certificate when connecting using TLS. Cannot be used toghether with TrustServerCertificateCA
TrustServerCertificateCA<path>Path to a pem, crt or der certificate file. Cannot be used together with TrustServerCertificate
encrypttrue,false,yes,no,DANGER_PLAINTEXTSpecifies whether the driver uses TLS to encrypt communication.
Application Name, ApplicationName<string>Sets the application name for the connection.
Source

pub fn from_jdbc_string(s: &str) -> Result<Self>

Creates a new Config from a JDBC connection string.

See from_ado_string method for supported parameters.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more