Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with connecting to PostgreSQL database #789

Open
wis-niowy opened this issue Mar 28, 2023 · 1 comment
Open

Issue with connecting to PostgreSQL database #789

wis-niowy opened this issue Mar 28, 2023 · 1 comment

Comments

@wis-niowy
Copy link

wis-niowy commented Mar 28, 2023

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):

  • OS: Windows 10

Additional context

@JulesNP
Copy link

JulesNP commented Jun 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants