prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
311 stars 113 forks source link

Dynamic Ports in Docker? #345

Open nateybear opened 1 month ago

nateybear commented 1 month ago

I'm on a Mac, running a SQL Server database via Docker. When I try to connect and execute queries via sqlcmd, I am able to. However, tiberius is not working for me. It appears that SQL Server is allocating a dynamic port for some reason. I guess my questions are:

  1. Why is the tiberius connection being given a dynamic port when sqlcmd isn't? This isn't a named instance, which afaik is what triggers mssql to allocate a dynamic port.
  2. Is there a workaround? I only see options for using SCM to turn off dynamic ports. I can't find any configuration via env vars or the mssql command that can turn it off. I would prefer not to forward all of my ports to the docker container, if possible.

Any advice is very much appreciated 🙂

Repro:

use tiberius::Config;
use tokio::net::TcpStream;
use tokio_util::compat::TokioAsyncWriteCompatExt;

#[tokio::main]
async fn main() -> Result<()> {
    let tcp = TcpStream::connect(Config::new().get_addr()).await?;
    println!("{:?}", tcp);
    Ok(())
}

Outputs: PollEvented { io: Some(TcpStream { addr: [::1]:61434, peer: [::1]:1433, fd: 11 }) }