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:
opened 12:57PM - 30 Nov 23 UTC
I' have problems trying to connect to SQL Server with Tiberius.
I was trying t… o use rustls instead of the default, but I don't get Tiberius to compile
```
[package]
name = "getsam"
version = "0.1.0"
edition = "2021"
[dependencies]
tiberius = { version = "0.12.2", features = ["rustls"] }
tokio = { version = "1.34.0", features = ["full"] }
```
The Tiberius crate does not compile. Any ideas ?
```
Compiling tiberius v0.12.2
error[E0428]: the name `create_tls_stream` is defined multiple times
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:31:1
|
23 | / pub(crate) async fn create_tls_stream<S: AsyncRead + AsyncWrite + Unpin + Send>(
24 | | config: &Config,
25 | | stream: S,
26 | | ) -> crate::Result<TlsStream<S>> {
27 | | TlsStream::new(config, stream).await
28 | | }
| |_- previous definition of the value `create_tls_stream` here
...
31 | / pub(crate) async fn create_tls_stream<S: AsyncRead + AsyncWrite + Unpin + Send>(
32 | | config: &Config,
33 | | stream: S,
34 | | ) -> crate::Result<TlsStream<S>> {
35 | | native_tls_stream::create_tls_stream(config, stream).await
36 | | }
| |_^ `create_tls_stream` redefined here
|
= note: `create_tls_stream` must be defined only once in the value namespace of this module
error[E0252]: the name `TlsStream` is defined multiple times
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:17:16
|
14 | pub(crate) use native_tls_stream::TlsStream;
| ---------------------------- previous import of the type `TlsStream` here
...
17 | pub(crate) use rustls_tls_stream::TlsStream;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `TlsStream` reimported here
|
= note: `TlsStream` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
17 | pub(crate) use rustls_tls_stream::TlsStream as OtherTlsStream;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0624]: associated function `new` is private
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:16
|
27 | TlsStream::new(config, stream).await
| ^^^ private associated function
|
::: /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-native-tls-0.4.0/src/tls_stream.rs:23:5
|
23 | pub(crate) fn new(stream: native_tls::TlsStream<StdAdapter<S>>) -> Self {
| ----------------------------------------------------------------------- private associated function defined here
error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:5
|
27 | TlsStream::new(config, stream).await
| ^^^^^^^^^^^^^^ ------ unexpected argument of type `S`
|
note: expected `TlsStream<StdAdapter<_>>`, found `&Config`
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:20
|
27 | TlsStream::new(config, stream).await
| ^^^^^^
= note: expected struct `native_tls::TlsStream<async_native_tls::std_adapter::StdAdapter<_>>`
found reference `&config::Config`
note: associated function defined here
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-native-tls-0.4.0/src/tls_stream.rs:23:19
|
23 | pub(crate) fn new(stream: native_tls::TlsStream<StdAdapter<S>>) -> Self {
| ^^^
help: remove the extra argument
|
27 - TlsStream::new(config, stream).await
27 + TlsStream::new(/* stream */).await
|
error[E0277]: `async_native_tls::TlsStream<_>` is not a future
--> /Users/pieter/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tiberius-0.12.2/src/client/tls_stream.rs:27:36
|
27 | TlsStream::new(config, stream).await
| -------------------------------^^^^^
| | ||
| | |`async_native_tls::TlsStream<_>` is not a future
| | help: remove the `.await`
| this call returns `async_native_tls::TlsStream<_>`
|
= help: the trait `futures_util::Future` is not implemented for `async_native_tls::TlsStream<_>`
= note: async_native_tls::TlsStream<_> must be a future or must implement `IntoFuture` to be awaited
= note: required for `async_native_tls::TlsStream<_>` to implement `std::future::IntoFuture`
Some errors have detailed explanations: E0061, E0252, E0277, E0428, E0624.
For more information about an error, try `rustc --explain E0061`.
error: could not compile `tiberius` (lib) due to 5 previous errors
````
[dependencies]
tiberius = { version = "0.12.2", default-features = false, features = ["rustls"] }
1 Like