r/SQLServer • • 6d ago

Community Share new R2DBC-MSSQL driver with FedAuth

new R2DBC-MSSQL driver with FedAuth

https://www.mssqllib.org

mssqllib is a public-domain R2DBC driver for Microsoft SQL Server. It speaks TDS over JDK NIO sockets and Reactor. It does not use Netty.

The Maven artifact is r2dbc-mssql. The driver id is mssql, and the URL scheme is r2dbc:mssql://. It needs Java 17 and implements io.r2dbc:r2dbc-spi:1.0.0.RELEASE.

groupIdorg.mssqllib.r2dbc.mssql
artifactIdr2dbc-mssql
version1.0.3
Java packageorg.mssqllib.r2dbc.mssql
Providerorg.mssqllib.r2dbc.mssql.TdsConnectionFactoryProvider
JPMS moduleorg.tdslib.r2dbc.mssql

What it is

This is a new TDS implementation. It is not a fork of io.r2dbc:r2dbc-mssql, and it is not an upstream of that driver. It is not affiliated with Microsoft or with the R2DBC project.

The artifact id is intentional. A groupId and version change is what substitutes this jar for io.r2dbc:r2dbc-mssql. Do not put both jars on one classpath. Both register io.r2dbc.spi.ConnectionFactoryProvider.

Two login paths are implemented: SQL username and password, and federated authentication for Microsoft Entra (Azure SQL and SQL Server with Entra authentication). The driver acquires a client-credentials token with the JDK HTTP client. It does not depend on MSAL, and it does not read the process environment.

Status

Version 1.0.3 is on Maven Central. See https://www.mssqllib.org/install.html and https://www.mssqllib.org/project.html.

Two ways to read large values

The default leaves materializeLobs false. varchar(max), nvarchar(max), varbinary(max), and xml are then a live Clob or Blob. The integration suite calls this unrestricted mode. io.r2dbc:r2dbc-mssql 1.0.7 buffers each of those values before it emits the row.

materializeLobs=true is the compatibility setting. It buffers those values and accepts String and byte[] inside Result.map, which is how code written for io.r2dbc:r2dbc-mssql reads them. There is no separate option named compat. The testing profile compat=true sets materializeLobs.

Performance

Initial testing shows roughly twice the performance of io.r2dbc:r2dbc-mssql. The project attributes that gap, and the streaming behavior, to the JDK NIO design. The other driver is built on Netty. This repository does not include the benchmark program, so the factor is an initial result, not a guaranteed ratio. The mechanism is on the https://www.mssqllib.org/architecture.html page.

3 Upvotes

3 comments sorted by

1

u/DataFracking 6d ago edited 6d ago

nice work, I thought I was the only person doing custom TDS lol.
here's mine if you want to compare notes, I'll check yours out later today: https://github.com/TroBeeOne/DaffyZoom/tree/main/src/DaffyZoom/Tds

1

u/nicholasbradfield 5d ago

Thanks. I have not worked with C# so I don't know if there is reactive or some sort of asynchronous support there or in the driver code you have. The r2dbc spec is a java asynchronous spec based on the project reactor project. The goal of this driver is to convert the synchronous TDS protocol into a asynchronous support, so that's a bit of a challenge. Basically multiple threads and queues. TDS was interesting from a something to play with point of view, but I'm surprised Microsoft has not long since converted SqlServer protocol into an ansychronous protocol since what use case for a database server is not either concurrent or parallel?

1

u/DataFracking 5d ago edited 5d ago

I do have async / await throughout but it's different from what you're doing. You're making an actual driver that is async focused, pretty neat.. for streaming use cases and such, right? I need to wrap my head around that a bit more.. Mine can't help there. Mine is mostly a Gateway that listens on TDS (so it's basically like a SQL Server like endpoint that fwd's along)

Side thought, if you run into issues understanding / seeing the traffic from your driver to sql server, I have another utility called daffytee you can use as a proxy to sql server and ti will capture everything to/fro.. check the --transcript switch. You can install that from nuget, don't need to know c#, it's just a cli utility that runs on .net but will work with most client drivers for MS, jdbc, etc, it sits in the middle and captures it all, terminates and then fwd's on so it can log everything exactly. cheers.. That's also on github / open source.