fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

Issue with connecting to PostgreSQL database #789

Open wis-niowy opened 1 year ago

wis-niowy commented 1 year ago

Describe the bug I am trying to establish a connection with PostgreSQL. Following this docs site: https://fsprojects.github.io/SQLProvider//core/postgresql.html I have copied Npgsql.dll in the chosen location and provided a path to this location as a ResolutionPath argument. I have this code to achieve the connection: ` module Postgresql = open FSharp.Data.Sql

let [<Literal>] connectionString = "Host=localhost; Database=TestDb; Username=postgres;Password=postgres"
let [<Literal>] resolutionPath = @"C:\Users\%user%\source\repos\MySolution"
// create a type alias with the connection string and database vendor settings
type sql = SqlDataProvider< 
              ConnectionString = connectionString,
              DatabaseVendor = Common.DatabaseProviderTypes.POSTGRESQL,
              ResolutionPath = resolutionPath,
              IndividualsAmount = 1000,
              UseOptionTypes = Common.NullableColumnType.OPTION
              >
let ctx = sql.GetDataContext()

` The error that I get when trying to build the project (via CLI) is as follows:

C:\Users\%user%\source\repos\Wisniowy.FSharpUtils\Wisniowy.FSharpUtils.DatabaseAccess\Library.fs(12,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not create the connection, most likely this means that the connectionString is wrong. See error from Npgsql to troubleshoot: Could not load file or assemb
ly 'Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. [C:\Users\%user%\source\repos\Wisniowy.FSharpUtils\Wisniowy.FSharpUtils.DatabaseAccess\Wisniowy.FSharpUtils.DatabaseAccess.fsproj]
C:\Users\%user%\source\repos\Wisniowy.FSharpUtils\Wisniowy.FSharpUtils.DatabaseAccess\Library.fs(12,16): error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not create the connection, most likely this means that the connectionString is wrong. See error from Npgsql to troubleshoot: Could not load file or assemb
ly 'Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. [C:\Users\%user%\source\repos\Wisniowy.FSharpUtils\Wisniowy.FSharpUtils.DatabaseAccess\Wisniowy.FSharpUtils.DatabaseAccess.fsproj]

So I focus mostly on the first line: "The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Microsoft.Data.SqlClient is not supported on this platform." I have Microsoft.Data.SqlClient installed in this project, all my nuget packages are: SQLProvider - v.1.3.7 Npgsql - v.7.0.2 Microsoft.Data.SqlClient - v.5.1.0

To Reproduce Steps to reproduce the behavior:

  1. Copy the code provided above
  2. Make sure you have an instance of PostgreSQL (or a docker container)
  3. Try to run the code

Expected behavior Successful connection with the db and a successful sample read done..

Screenshots The error displayed when I hover over the code sample: image and when I build the solution with ctrl+shift+B (same error) image The dll files added to the "resolution path" location: image I added Npgsql.dll along with two other dlls according to some suggestion I had found on stack overflow (they are the external dependencies that Npgsql.dll has and that it needs)

Desktop (please complete the following information):

Additional context

JulesNP commented 1 year ago

I'm experiencing the same issue on both Windows 11 and MacOS. Using Npgsql directly works, but when using it via SqlDataProvider it fails.