I'm learning rust and I've written my first very simple API using Rocket. Now I'd like to connect my server to an existing database I've got on MSFT Azure. I'm having a hard time finding examples on how this works for Mssql, the SQLx repository only contains examples for Postgres and MySQL.
There is no connection string on the Azure Portal available for rust, so I've experimented with different versions for Go and ODBC:
const SERVER: &str = "<mysqlserver>.database.windows.net";
const PORT: &str = "1433";
const USER: &str = "sqladmin";
const PASSWORD: &str = "<mypassword>";
const DATABASE: &str = "<mydatabase>";
MssqlConnection::connect(&format!("server={};user id={};password={};port={};database={};", SERVER, USER, PASSWORD, PORT, DATABASE)[..]).await?;
This gives an Error: Configuration(RelativeUrlWithoutBase)
so I think SQLx expects a connection string like "postgres://..."
, I can't find this string for mssql though.
CodePudding user response:
Although I'm still not able to connect to the SQL Server on Azure, the problem of finding the right connection string format has been solved. I was able to connect to a local server using:
MssqlConnection::connect("mssql://user:password@server/database").await?;
So the connection string follows the same schema as e.g. Postgres, it's unfortunate that none of the example strings on the Azure Portal are of this type.
Edit: The connection issues are most likely due to the lack of support for encrypted connections, more details here.