Expand description
Microsoft SQL Server driver for SQLx.
sqlx-sqlserver is an independent split driver crate. Use it directly with
sqlx-core native APIs, or install its Any driver when an
application wants to open SQL Server URLs through AnyConnection.
§Native connection
use sqlx_core::connection::{ConnectOptions, Connection};
use sqlx_core::row::Row;
use sqlx_sqlserver::MssqlConnectOptions;
let mut conn = "mssql://sa:Password123!@localhost:1433/master?encrypt=mandatory&trust_server_certificate=true"
.parse::<MssqlConnectOptions>()?
.connect()
.await?;
let row = sqlx_core::query::query("SELECT 1")
.fetch_one(&mut conn)
.await?;
let value: i32 = row.try_get(0)?;
assert_eq!(value, 1);
conn.close().await?;§AnyConnection
Install this driver before connecting through SQLx Any APIs:
use sqlx_core::connection::Connection;
sqlx_core::any::driver::install_drivers(&[sqlx_sqlserver::any::DRIVER])?;
let mut conn = sqlx_core::any::AnyConnection::connect(
"mssql://sa:Password123!@localhost:1433/master?encrypt=mandatory&trust_server_certificate=true",
)
.await?;
conn.close().await?;To combine split drivers, install all of them once at application startup:
ⓘ
fn install() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
sqlx_core::any::driver::install_drivers(&[
sqlx_sqlserver::any::DRIVER,
sqlx_odbc::any::DRIVER,
])?;
Ok(())
}The examples use trust_server_certificate=true for local development with
SQL Server’s self-signed container certificate. Production deployments should
prefer a trusted certificate and, when needed, hostname_in_certificate or
ssl_root_cert in MssqlConnectOptions.
Re-exports§
pub use options::Encrypt;pub use options::MssqlConnectOptions;pub use options::MssqlInvalidOption;
Modules§
- any
- Runtime
Anydriver registration for SQL Server. - options
- Connection option parsing and configuration for SQL Server.
- protocol
- Small protocol helpers covered by fast unit tests.
Structs§
- Mssql
- SQL Server database driver marker.
- Mssql
Arguments - SQL Server argument buffer.
- Mssql
Column - SQL Server column metadata skeleton.
- Mssql
Connection - SQL Server connection.
- Mssql
Database Error - An error reported by SQL Server.
- Mssql
Query Result - Summary of a SQL Server query execution.
- Mssql
Row - SQL Server row skeleton.
- Mssql
Statement - SQL Server prepared statement metadata skeleton.
- Mssql
Transaction Manager - SQL Server transaction manager.
- Mssql
Type Info - SQL Server type information.
- Mssql
Value - Owned SQL Server value skeleton.
- Mssql
Value Ref - Borrowed SQL Server value skeleton.
Enums§
- Mssql
Type - SQL Server scalar type families known by the skeleton driver.
Traits§
- Mssql
Executor - An alias for
Executor<'_, Database = Mssql>.
Type Aliases§
- Mssql
Pool - An alias for
Pool, specialized for SQL Server. - Mssql
Pool Options - An alias for
PoolOptions, specialized for SQL Server. - Mssql
Transaction - An alias for
Transaction, specialized for SQL Server.