rust connect sql server database
Cargo.toml add deps
deadpool-tiberius = {version = "0.1.8", features = ["all"]}
dotenv = "0.15.0"
.env file
DB_HOST="localhost"
DB_USER="ss"
DB_PASSWORD="Z@dd"
DB_NAME="rr"
main.rs
fn main(){ // Get the values dotenv::dotenv().ok(); let db_host = env::var("DB_HOST").expect("DB_HOST must be set"); let db_user = env::var("DB_USER").expect("DB_USER must be set"); let db_password = env::var("DB_PASSWORD").expect("DB_PASSWORD must be set"); let db_name = env::var("DB_NAME").expect("DB_NAME must be set"); let pool = deadpool_tiberius::Manager::new() .host(db_host) .port(1433) .basic_authentication(db_user, db_password) .database(db_name) .max_size(20) .trust_cert() .wait_timeout(1.52) .pre_recycle_sync(|_client: &mut Client, _metrics: &Metrics| Ok(())) .create_pool() .unwrap(); }