With the release of .NET Core 2.0.4 it’s finally possible to use SqlProvider on a netcoreapp2.0 project against a Microsoft SQL Server database.

Having spent a couple of hours every night the last week trying to get this to work properly and running into all sorts of fun stuff I hope I can save someone else some time (and frustration) with this.

There a couple of things that needs to be done to get this to work, so let’s get going.

I will be using VSCode with Ionide and the dotnet-cli version 2.1.3 on Windows. (you can download the latest .NET Core 2.0.4 SDK with everything you need here https://github.com/dotnet/core/blob/master/release-notes/download-archives/2.0.4-download.md.

Create a new project with:

dotnet new console -lang F# -o SqlProviderTestApp

2. Add the following two lines to the first PropertyGroup in SqlProviderTestApp.fsproj under the TargetFramework tag.

<FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0</FscToolPath><FscToolExe>fsc.exe</FscToolExe>

3. Add the SqlProvider and the System.Data.SqlClient package to the project with:

dotnet add package SqlProvider

dotnet add package System.Data.SqlClient

4. Add a PostBuild step at the bottom of SqlProviderTestApp.fsproj :

<Target Name="PostBuild" AfterTargets="PostBuildEvent">

<Exec Command="copy ..\..\..\.nuget\packages\System.Data.SqlClient\4.4.0\runtimes\win\lib

etstandard2.0\System.Data.SqlClient.dll bin\Debug

etcoreapp2.0\" />

</Target>

5. Build the project (this is important, otherwise you don’t get any code completion in VSCode).

dotnet build

6. Enter some code in Program.fs that uses SqlProvider:

7. Profit! Now you should be able to enjoy the power that F# and SqlProvider provides.

Till next time!