2

I'm using SQLProvider to connect to my (local) PostgreSQL database in F#. I've started with this code from fsprojects:

open FSharp.Data.Sql
open Npgsql

let [<Literal>] ResolutionPath = 
    __SOURCE_DIRECTORY__ + @"/../../packages/Npgsql/lib/net451/"

[<Literal>]
let connectionString = "Host=localhost;Port=5432;User ID=test;Password=test;Database=testdb;"

 type PostgreSQL = 
    SqlDataProvider< 
        Common.DatabaseProviderTypes.POSTGRESQL,
        ConnectionString  = connectionString,
        ResolutionPath    = ResolutionPath,
        IndividualsAmount = 1000,
        UseOptionTypes    = true>

When I'm trying to compile it I get this error message:

(path)/Database.fs(60,9): 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: The type initializer for 'Npgsql.Counters' threw an exception. (path)/Database.fs(60,9): 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: The type initializer for 'Npgsql.Counters' threw an exception.

I've checked that user id and password and everything in connection string is correct. I actually don't have any idea how to debug this issue. Do you know what could be wrong? Does it work for you without any issues?

I'm using macOS 10.12.

And lastly, in case I won't be able to fix this, are there any other methods that you would recommend for connecting to postgreSQL (with type providers)?

3
  • try username instead of user id as per fsprojects.github.io/SQLProvider/core/postgresql.html Commented Feb 24, 2017 at 21:01
  • Both versions don't work, I've tried "Username" instead of User Id, same result. Commented Feb 24, 2017 at 21:01
  • 1
    I would also try npgsql 3.1 as in the answer below, had some problems with 3.2 on windows as well. Not including the massive the .net core dependency downloads, but at least paket can clean that up. Commented Feb 25, 2017 at 11:51

1 Answer 1

4

The error message clearly says that an exception was thrown from the type initializer for Npgsql.Counters - this is Npgsql 3.2's new support for Windows performance counters.

Unfortunately it seems that there are several issues with performance counters in various scenario (see #1447 and #1435). Because of this, version 3.2.2 (to be released this week) won't make use of them by default.

Can you please confirm that you're using 3.2.1 (and not 3.2.0), because a partial fix was introduced? If you're using 3.2.1 and getting this exception, you'll have to wait a few days for 3.2.0, and can use 3.1.10 in the meantime where the exception won't be thrown.

Sign up to request clarification or add additional context in comments.

2 Comments

Version 3.1.10 compiles without issues, but I don't get any autocompletion or types from SQLProvider.
That's a different issue... I have no idea how F# SQLProvider does its magic - according to its doc page it seems that Npgsql is fully supported. It would be good to check with another provider (SQLServer/Sqlite) to make sure things work as you expect them too. If you think there's some Npgsql-specific issue, you're welcome to open an issue on the Npgsql github repo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.