### Handle Azure Firewall Redirects with Tiberius Source: https://github.com/prisma/tiberius/blob/main/README.md Use this code to establish a connection to a SQL Server, handling potential routing errors by redirecting to a new host and port. Ensure you have the necessary dependencies like `tiberius` and `tokio`. ```rust use tiberius::{Client, Config, AuthMethod, error::Error}; use tokio_util::compat::TokioAsyncWriteCompatExt; use tokio::net::TcpStream; #[tokio::main] async fn main() -> Result<(), Box> { let mut config = Config::new(); config.host("0.0.0.0"); config.port(1433); config.authentication(AuthMethod::sql_server("SA", "")); let tcp = TcpStream::connect(config.get_addr()).await?; tcp.set_nodelay(true)?; let client = match Client::connect(config, tcp.compat_write()).await { // Connection successful. Ok(client) => client, // The server wants us to redirect to a different address Err(Error::Routing { host, port }) => { let mut config = Config::new(); config.host(&host); config.port(port); config.authentication(AuthMethod::sql_server("SA", "")); let tcp = TcpStream::connect(config.get_addr()).await?; tcp.set_nodelay(true)?; // we should not have more than one redirect, so we'll short-circuit here. Client::connect(config, tcp.compat_write()).await? } Err(e) => Err(e)?, }; Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.