我正在使用SQLProvider连接到我在F#中的本地PostgreSQL数据库。 我已经开始使用此代码fsprojects:Npgsql抛出一个错误:错误的连接字符串。无法连接到PostgreSQL [F#]
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>
当我试图编译它,我得到这个错误信息:
(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.
我检查该用户ID和密码,一切在连接字符串中是正确的。 我其实不知道如何调试这个问题。 你知道什么可能是错的? 它对你没有任何问题吗?
我使用的是macOS 10.12。
最后,如果我不能解决这个问题,有没有其他方法,你会建议连接到PostgreSQL(与类型供应商)?
按照http://fsprojects.github.io/SQLProvider/core/postgresql.html –
尝试用户名而不是用户标识 这两个版本都不起作用,我试过“用户名”而不是用户ID,相同结果。 – mateuszlewko
我也会尝试npgsql 3.1,如下面的答案,在Windows上也有一些3.2的问题。不包括大规模的.net核心依赖性下载,但至少可以清除那些。 – s952163