0

I am trying to read SQL Server data to polars DataFrame in Rust with connectorx. However, I never succeeded with windows authentication. When run, it returns

Query failed: SourceNotSupport("MsSQL")

The code is below.

// main.rs

use polars::prelude::*;
use connector::prelude::*;

fn main(){
   let bs_df: DataFrame = create_df_connectorx();
   println!("{:?}", bs_df);
}

fn create_df_connectorx() {
   let connection_str: &str = "mssql://sample_servername/sample_databasename?integratedSecurity=true";
   let source_conn: SourceConn = SourceConn::try_from(connection_str).expect(msg:"failed to create connection");
   
    let queries:  &[CXQuery;1] = &[CXQuery::from("select * from sample_tablename")];


    //error occurs on this line
    let destination: Arrow2Destination=connectorx::get_arrow2::get_arrow2(
            &source_conn,
            None,
            queries).expect(msg: "Query failed");

    let df: DataFrame = rlt.polars().unwrap();
    df     
}

//Cargo.toml

[package]
name="query_sqlserver"
version="0.1.0"
edition="2021"

[dependencies]
connectorx={version="^0.3.3", features=["dst_arrow2"]}
polars={version="0.32"}

Did not get a chance to try the connection with account name and password for the default way to login to the company database is windows authentication.

Maybe I missed something important, I searched this topic but did not find an example that connectorx reads data from mssql with windows authentication. And not even sure if connectorx support mssql windows authentication now (there are examples to query with account name and password).

3
  • Where's the read_database call? connectorx::get_arrow2 isn't a Polars method. Have you tried using connectorx's read_sql method instead of get_arrow2 ? connectorx supports SQL Server but this particular method may not Commented Nov 14, 2024 at 8:25
  • integratedSecurity? Have you tried trusted_connection=true as per the connector-x docs? Commented Nov 14, 2024 at 9:32
  • Hi @AlwaysLearning, thanks for the comment. I tried trusted_connection=true which does not make a difference. What surprised me is, I tried the same code on my personal laptop with a PostGreSQL database (connection string updated accordingly), last night I got a SourceNotSupport("Postgre") error. Commented Nov 15, 2024 at 4:05

1 Answer 1

0

Evening,

I came into the same issue: the features for each connecting to each database are behind a feature flag, and need to be manually enabled; see the relevant source file for Postgres here.

As such, your Cargo.toml should like like this:

[dependencies]
connectorx = { version = "0.3.3", features = ["dst_arrow", "src_postgres", "src_mssql"] }
polars = { version = "0.32" }

I hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.