Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid peer certificate: UnsupportedCertVersion #327

Open
ryanhossain9797 opened this issue Jan 30, 2024 · 0 comments
Open

invalid peer certificate: UnsupportedCertVersion #327

ryanhossain9797 opened this issue Jan 30, 2024 · 0 comments

Comments

@ryanhossain9797
Copy link

ryanhossain9797 commented Jan 30, 2024

I'm getting this error running the example code

Error: An error occured during the attempt of performing I/O: invalid peer certificate contents: invalid peer certificate: UnsupportedCertVersion

Cargo.toml

tiberius = { version = "0.12.2", default-features = false, features = [ "rustls" ] }
once_cell = { version = "1.19" }
anyhow = { version = "1.0" }
tokio-util = { version = "0.7", features = [ "compat" ] }
tokio = { version = "1.35", features = ["full"] }

Code

use once_cell::sync::Lazy;
use std::env;
use tiberius::{Client, Config};
use tokio::net::TcpStream;
use tokio_util::compat::TokioAsyncWriteCompatExt;

static CONN_STR: Lazy<String> = Lazy::new(|| {
    env::var("TIBERIUS_TEST_CONNECTION_STRING").unwrap_or_else(|_| {
        "Server=localhost;Database=
<my_db>;User ID=<my_user_id>;Password=<my_known_password>;Trusted_Connection=False;Encrypt=False;MultipleActiveResultSets=True;".to_owned()
    })
});

#[cfg(not(all(windows, feature = "sql-browser-tokio")))]
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = Config::from_ado_string(&CONN_STR)?;

    let tcp = TcpStream::connect(config.get_addr()).await?;
    tcp.set_nodelay(true)?;

    let mut client = Client::connect(config, tcp.compat_write()).await?;

    let stream = client.query("SELECT TOP 10 * FROM [Accounting].[Account]", &[&1i32]).await?;
    let row = stream.into_row().await?.unwrap();

    println!("{:?}", row);
    assert_eq!(Some(1), row.get(0));

    Ok(())
}

Note that the connection string works locally from ssms or azure data studio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant