Error connecting to mssql using tiberius

Rust newbie...I'm trying to connect to an MSSQL instance using tiberius but I'm not able to connect. I've tried two separate mssql instances hosted on Google Cloud and Azure with the same result.

Any ideas??

The error I get is:

Error: Tls("connection closed via error")
    let addr = "host:1433";
    let tcp = tokio::net::TcpStream::connect(addr).await?; // tcp connection ok
    tcp.set_nodelay(true)?;
    let auth = AuthMethod::sql_server("user","pass");
    let mut config = Config::new();
    config.host("xxxx.database.windows.net");
    config.port(1433);
    config.database("xxx");
    config.authentication(auth);
    let client = Client::connect(config, tcp.compat()).await?; // This fails
    println!("Ok");
    Ok(())

My deps:

[dependencies]
async-std = {version="1.12.0", features = ["attributes"]}
once_cell = "1.19.0"
anyhow = "1.0.86"
time = "0.3.36"
tokio = { version = "1.37.0", features = [
    "full"
] }
tokio-util = { version = "0.7.11", features = ["compat"] }
http = "1.1.0"
read-write-ext-tokio = "0.1.0"

Does Config::trust_cert fix it? Your example doesn’t seem to configure the cert at all.

I was able to resolve this issue by including the rustls feature. I think this is required if running on a Mac.

Here is a link to a similar issue:

[dependencies]
tiberius = { version = "0.12.2", default-features = false, features = ["rustls"] }

1 Like