fsprojects/SQLProvider

Unable to make SQLProvider work on WSL with .NET 5 and FSI

esbenbjerre opened this issue · 7 comments

Describe the bug
I want to use SQLProvider with SQL Server in .NET 5 FSI. I'm using WSL (Ubuntu) on Windows. No matter how I try to load it, it does not work. I have tried various workarounds posted here and online.
I've tried:

  • Just using #r "nuget: SQLProvider"
  • Copying and referencing the dlls with ResolutionPath

No matter how I try I get one of these errors on dotnet fsi script.fsx:

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: System.Data.SqlClient is not supported on this platform.

or

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Exception has been thrown by the target of an invocation.

or

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.Identity.Client, Version=4.22.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. The system cannot find the file specified.

Could not load file or assembly 'Azure.Core, Version=1.6.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.Identity.Client, Version=4.22.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. The system cannot find the file specified.

Details: 
Could not load file or assembly 'Microsoft.Identity.Client, Version=4.22.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae'. The system cannot find the file specified.

Could not load file or assembly 'Azure.Core, Version=1.6.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'. The system cannot find the file specified.

Current execution platform: .NETCoreApp,Version=v3.1

To Reproduce
Create blank project

dotnet new console -lang F# -o Test
cd Test
dotnet add package SQLProvider

Try to use SQLProvider from FSI

type Sql = SqlDataProvider<DatabaseVendor = Common.DatabaseProviderTypes.MSSQLSERVER_SSDT, ConnectionString = "secret">
let ctx = Sql.GetDataContext()

Expected behavior
A working SQLProvider.

Also does not work on mac os .NET 6 and FSI

essic commented

I can't make it work as well on OSX within a .NET 6 console app.

Screen Shot 2022-06-02 at 01 49 51

I tried using MSSQLSERVER_DYNAMIC and the ResolutionPath but it didn't work as well.

I use paket to make sure FSharp.Core & co are on point. I use FSharp.Core 6.0.4

Here's my paket.dependencies :
Screen Shot 2022-06-02 at 01 54 41

Here's my paket.references for the console app :
Screen Shot 2022-06-02 at 01 55 45

If anything else is needed, please let me know.

I tried using MSSQLSERVER_DYNAMIC and the ResolutionPath but it didn't work as well.

You should be using Microsoft.Data.SqlClient in conjunction with MSSQLSERVER_DYNAMIC and the ResolutionPath.

essic commented

Hello,

Thanks for the reply.
I tried but I still got issue.
What Dlls should I copy in the resolution path ?

What Dlls should I copy in the resolution path ?

It should be these:

To use another driver, Microsoft.Data.SqlClient.dll, you have to set your provider to Common.DatabaseProviderTypes.MSSQLSERVER_DYNAMIC and copy the reference files from the NuGet package to local resolutionPath 

(e.g. Microsoft.Data.SqlClient.dll, Microsoft.Data.SqlClient.SNI.dll and Microsoft.Data.SqlClient.SNI.x86.dll).
essic commented

Hello again,

I had to take a break from that issue but I'm back.
I tried your solution but it does not work.

I am currently using a fsx for my need.
Is there a way, I can get the details of the exception ? So far I just have the folowing :
image

I tried 'dotnet fsi --debug' bug I don't have the stack trace.

Thanks again for your help.

I tried using MSSQLSERVER_DYNAMIC and the ResolutionPath but it didn't work as well.

You should be using Microsoft.Data.SqlClient in conjunction with MSSQLSERVER_DYNAMIC and the ResolutionPath.

Using VS2022, in a console app targeting .net 6.0, I'm getting this error:
error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.�Details: �Cannot load a reference assembly for execution.�Could not load type 'System.Data.Common.DbCommandBuilder' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.�Could not load type 'System.Data.Common.DbDataAdapter' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.�Could not load type 'System.Data.Common.RowUpdatedEventArgs' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.�Could not load type 'System.Data.Common.RowUpdatingEventArgs' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.�Could not load type 'System.Data.Common.DbDataSourceEnumerator' from assembly 'System.Data.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.�Current execution platform: .NETFramework,Version=v4.7.2

This is in my resolution path:
image