2017-02-24 41 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上打開一個問題。 –