fsprojects / fsprojects/FSharp.Data.SqlClient

Any 2023 tricks for running on Windows?

Open
#427 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
F#
Stars
206
Forks
66
PR merge metrics
No merged PRs in 30d

Description

What are the tips, tricks, and hacks for making FSharp.Data.SqlClient run on Windows in 2023? In other words: What is smallest working example project for Windows?

I have been happily using FSharp.Data.SqlClient in a project that I develop on macOS and deploy to Azure Functions (Linux). I have had no problems after finding the initial trick to load System.Data.SqlClient (https://github.com/fsprojects/FSharp.Data.SqlClient/issues/373#issuecomment-1225511421).

But now I would like my colleagues with Windows machine to be able contribute to the project. But I don't know how to solve the build error: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.

Repro Steps

OS: Windows 10
.NET SDK: 7.0.202

Test.fs
open FSharp.Data

[<Literal>]
let connStr = "...insert-connnection-string-here..."

type MyCommand = SqlCommandProvider<"SELECT 42 as myNumber, 'hello' as myString", connStr>

(new MyCommand(connStr)).Execute() |> printfn "%A"
Test.fsproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Test.fs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="FSharp.Data.SqlClient" Version="2.1.2" />
  </ItemGroup>
  
  <!-- tricks -->
  <ItemGroup>
    <PackageReference Include="System.Data.SqlClient" Version="4.8.5">
      <ExcludeAssets>compile</ExcludeAssets>
    </PackageReference>
  </ItemGroup>
  <PropertyGroup>
    <OtherFlags>$(OtherFlags) -r:"C:\Users\my_user_name\.nuget\packages\system.data.sqlclient\4.8.5\runtimes\win\lib\netstandard2.0\System.Data.SqlClient.dll"</OtherFlags>
  </PropertyGroup>
</Project>

Run: dotnet build

Expected behavior

The build should succeed and work on Windows just like it does on macOS (with adjusted path to System.Data.SqlClient.dll).

Actual behavior

Build error:

Test.fs(7,18): error FS3033: The type provider 'FSharp.Data.
SqlCommandProvider' reported an error: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception.

There are no further details about the exception thrown by System.Data.SqlClient.TdsParser (even using dotnet build -v:d). Does anyone know how to get more details? Or completely solve this issue?

Related information

The trick to provide the System.Data.SqlClient.dll (https://github.com/fsprojects/FSharp.Data.SqlClient/issues/373#issuecomment-1225511421) works as excepted and solves this error: Test.fs(7,18): error FS3033: The type provider 'FSharp.Data. SqlCommandProvider' reported an error: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture =neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies cannot be loaded for execution. (0x80131058)

The connection string used for this experiment has been tested with a small project using System.Data.SqlClient directly, and it works as expected on the Windows machine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Test.fs and Test.fsproj, then run the supplied dotnet build reproduction on Windows and inspect the System.Data.SqlClient TdsParser failure. Compare the FSharp.Data.SqlClient and System.Data.SqlClient package and runtime-loading setup; done means the smallest example builds and runs on Windows without the type-initializer error.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp, sql
Domain
build-system, databases, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.