.netsql-serverf#

How to connect to MS SQL Server with F# with SQLProvider?


I'm trying to use the SQLProvider for MS SQL Server with F#, but it appears that it's not possible with the recommended setup.

See my module below:

namespace MyApp

open FSharp.Data.Sql

module Database =

    [<Literal>]
    let dbVendor = Common.DatabaseProviderTypes.MSSQLSERVER


    [<Literal>]
    let connString =
        "Data Source=localhost;Database=MyDatabase;User Id=user;Password='my-password-here'"

    [<Literal>]
    let indivAmount = 1000

    [<Literal>]
    let useOptTypes = true

    type sql = SqlDataProvider<dbVendor, connString, IndividualsAmount=indivAmount, UseOptionTypes=useOptTypes>

My main problem is that after adding in this code I get this message/warning in intellisense

The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: System.Data.SqlClient is not supported on this platform.F# Compiler(3033)

and a build error when attempting to compile:

Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Development\F#\MyApp\DataTypes.fs(21,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: System.Data.SqlClient is not supported on this platform. [C:\Development\F#\MyApp\MyApp.fsproj]
C:\Development\F#\MyApp\DataTypes.fs(21,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: System.Data.SqlClient is not supported on this platform. [C:\Development\F#\MyApp\MyApp.fsproj]

Build FAILED.

C:\Development\F#\MyApp\DataTypes.fs(21,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: System.Data.SqlClient is not supported on this platform. [C:\Development\F#\MyApp\MyApp.fsproj]
C:\Development\F#\MyApp\DataTypes.fs(21,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: System.Data.SqlClient is not supported on this platform. [C:\Development\F#\MyApp\MyApp.fsproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:06.21

Is there something that I'm doing wrong, or is this really just not possible to use the default setup along with latest .NET and F# and I need to submit a git issue? Any insights and critiques welcomed, thanks!

In use at the time of posting:


Solution

  • To resolve this issue, I opened the project within Visual Studio (v17 2022) and did the following:

    After doing the above I was able to run the application and get a connection to the database followed by a simple select query that returned expected data.

    Not sure why, but Ionide always gives the dreaded red squigglies even when things build just fine.