2017-02-24 77 views
1

我正在使用SQLProvider连接到我在F#中的本地PostgreSQL数据库。 我已经开始使用此代码fsprojectsNpgsql抛出一个错误:错误的连接字符串。无法连接到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(与类型供应商)?

+0

按照http://fsprojects.github.io/SQLProvider/core/postgresql.html –

+0

尝试用户名而不是用户标识 这两个版本都不起作用,我试过“用户名”而不是用户ID,相同结果。 – mateuszlewko

+1

我也会尝试npgsql 3.1,如下面的答案,在Windows上也有一些3.2的问题。不包括大规模的.net核心依赖性下载,但至少可以清除那些。 – s952163

回答

4

错误消息清楚地表明Npgsql.Counters的类型初始值设定项引发了一个异常 - 这是Npgsql 3.2对Windows性能计数器的新支持。

不幸的是,在各种情况下,性能计数器似乎有几个问题(请参阅#1447#1435)。因此,版本3.2.2(本周发布)默认情况下不会使用它们。

您能否确认您使用3.2.1(而不是3.2.0),因为引入了部分修复?如果你使用3.2.1并且得到这个异常,你将不得不等待3.2.0的几天,并且可以在不抛出异常的情况下使用3.1.10。

+1

版本3.1.10编译没有问题,但我没有从SQLProvider获得任何自动完成或类型。 – mateuszlewko

+1

这是一个不同的问题......我不知道F#SQLProvider如何发挥它的魔力 - 根据它的文档页面,似乎完全支持Npgsql。用另一个提供程序(SQLServer/Sqlite)检查以确保事物能够按照您的预期工作,这将是一件好事。如果您认为存在一些Npgsql特定的问题,欢迎您在Npgsql github repo上打开一个问题。 –