3

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:PASSWORD@SERVER.database.windows.net/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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
picklepick
  • 1,370
  • 1
  • 11
  • 24
  • Maybe you can try with another MSSQL server, e.g. a local one, to see if the code works. Also, double check if the Azure one uses the default port, 1433. It looks from the python code it does. – Joe_Jingyu Nov 19 '21 at 10:10
  • @Joe_Jingyu thanks for your suggestion. I am able to connect to an instance on localhost. `mssql://usr:pw@localhost/master`. Yes, it does use 1433 according to the documentation. – picklepick Nov 19 '21 at 11:12
  • If so, I don't think the issue is likely with the connection string or the other part of your code. Sorry I cannot think of anything else to look into or try on your side. If Azure can provide some server-side logs, you might find more detailed information of the cause. – Joe_Jingyu Nov 19 '21 at 12:06

1 Answers1

3

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

picklepick
  • 1,370
  • 1
  • 11
  • 24