-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An example how to connect using named pipes
- Loading branch information
Julius de Bruijn
committed
Mar 1, 2021
1 parent
f9c702d
commit d3f38d9
Showing
2 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#[cfg(windows)] | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
use tokio::net::windows::named_pipe::NamedPipe; | ||
use tokio_util::compat::TokioAsyncWriteCompatExt; | ||
use tiberius::{Config, AuthMethod, Client}; | ||
|
||
let mut config = Config::new(); | ||
config.authentication(AuthMethod::Integrated); | ||
config.trust_cert(); | ||
|
||
let pipe = NamedPipe::connect("\\\\.\\pipe\\sql\\query").await?; | ||
let mut client = Client::connect(config, pipe.compat_write()).await?; | ||
|
||
let stream = client.query("SELECT @P1", &[&1i32]).await?; | ||
let row = stream.into_row().await?.unwrap(); | ||
|
||
println!("{:?}", row); | ||
assert_eq!(Some(1), row.get(0)); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(not(windows))] | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
panic!("Only works on Windows."); | ||
} |