Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to SQL Server with SQLx

I'm having difficulties accessing my SQL Server database hosted on Azure via the SQLx library.

I am able to connect to my database using pymssql:

conn = pymssql.connect(server='SERVER.database.windows.net', user='USER', password='PASSWORD', database='DATABASE')  

Therefore, I assume that my settings in the Azure Portal are all correct and the problem lies indeed with my SQLx code.

Using the same credentials, I tried connecting to the database:

let mut connection = MssqlConnection::connect(
        "mssql://USER:[email protected]/DATABASE").await?;

However this results in

Error: Io(Kind(ConnectionAborted))

and according to the rust std::io error docs this error means:

The connection was aborted (terminated) by the remote server

I'm wondering whether this error message is accurate since I wouldn't know why the remote would terminate the connection. Furthermore, these calls don't show up in the metrics tab, therefore I'm thinking that the requests never made it to the server.

I'm importing the tokio and sqlx crates like this:

sqlx = { version = "0.5.9", features = [ "runtime-tokio-native-tls" , "mssql" ] }
tokio = { version = "1.14.0", features = ["full"] }

Does anyone know what this error means/what I'm doing wrong?

like image 612
picklepick Avatar asked Jul 22 '26 05:07

picklepick


1 Answers

I posted created an GitHub issue in the SQLx repository and got the following reply:

This may be due to our lack of support for encrypted connections: #414

It looks like this will not be solved in the near future:

... we will be closing up the source of the MSSQL driver we can no longer accept outside contributions to its code. If you are currently using MSSQL for non-profit or open-source purposes, you will be able to request a free license to use the upcoming closed-source driver. link

like image 170
picklepick Avatar answered Jul 23 '26 20:07

picklepick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!