Using System.Data.Sqlclient instead of Microsoft.Data.SqlClient when connecting to a Fabric datawarehouse

155 Views Asked by At

Using this example: https://robkerr.ai/query-fabric-table-csharp/

I can connect to my sqlserver Fabric Warehouse in Azure trough VS Code when using Microsoft.Data.SqlClient

My question is this : Is this possible to achive using System.Data.SqlClient? I just can't make it work.

(This is part of a rather big solution and using Microsoft.Data.SqlClient raises all kind of other problems)

This code works fine

Imports Microsoft.Data.SqlClient
Dim connectionString As String = "Data Source=theCave.datawarehouse.pbidedicated.windows.net,1433;
                               Initial Catalog=TreASURE;
                               Authentication=ActiveDirectoryPassword;
                               User [email protected];  
                               Password=SesamSesam"

Dim conn As SqlConnection = New SqlConnection(connectionString)
conn.Open()

But when replacing Microsoft.Data.SqlClient with System.Data.Sqlclient I just cant make it work.

tnx

2

There are 2 best solutions below

0
David Browne - Microsoft On BEST ANSWER

Both System.Data.SqlClient and Microsoft.Data.SqlClient can connect to Fabric SQL endpoints.

Fabric SQL endpoints don't support SQL Auth or Windows Auth. Only Entra ID auth (formerly called AAD auth).

Microsoft.Data.SqlClient natively understands and implements several EntraId authentication flows. System.Data.SqlClient only understands a couple of Entra ID auth flows natively. But you can fetch an access token for Azure SQL Database using any auth flow you need, and set the .AccessToken property on a System.Data.SqlClient.SqlConnection to connect.

Follow the docs here: Connect using a Microsoft Entra ID access token

1
JayV On

Looking at the NuGet reference for this: https://www.nuget.org/packages?q=SqlClient

I see: enter image description here

The important part being:

Microsoft.Data.SqlClient

The current data provider for SQL Server and Azure SQL databases.

There is no such assertion for System.Data.SqlClient.

Therefore, I think it is safe to assume that System.Data.SqlClient does not work with Azure.