我通过SQLProvider访问SQLite数据库。我实际上可以连接到数据库并查询表中的数据。但是类型提供程序显示错误:Exception has been thrown by a target of an invocation
。智能感知并不能真正发挥作用,例如:表或属性不显示。请参见屏幕截图:
由于表和类型无法访问,因此在尝试访问属性时会显示lookup on object of indeterminate type
错误(但它确实有效)。从表中提取数据也很有效。因此类型提供程序可以访问数据库但显示这些错误。有没有办法让它正确识别数据库并访问其属性等,没有错误。
我使用的是64位SQLite驱动程序。这是代码:
#if INTERACTIVE
#r @"..\packages\SQLProvider.1.0.8\lib\FSharp.Data.SqlProvider.dll"
#r @"..\packages\System.Data.SQLite.Core.1.0.101.0\lib\net46\System.Data.SQLite.dll"
#r @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.Linq.dll"
#endif
open System
open FSharp.Data.Sql
[<Literal>]
let connectionString = "Data Source="+ @"C:\tmp\databaseFile.db3"
[<Literal>]
let resolutionPath = __SOURCE_DIRECTORY__ + @"..\..\packages\System.Data.SQLite.Core.1.0.101.0\lib\net46"
type sql = SqlDataProvider<
Common.DatabaseProviderTypes.SQLITE,
ConnectionString = connectionString,
ResolutionPath = resolutionPath,
CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL
>
let ctx = sql.GetDataContext()
let table2 = ctx.Main.Table2 //DateTime
let table3 = ctx.Main.Table3 //Text
query {
for r in table3 do
select (r.Date1)
} |> Seq.toList
query {
for r in table2 do
select (r.Date1)
} |> Seq.toList
答案 0 :(得分:2)
这适用于当前的SQLite和SQLTypeProvider(分别为1.0.102.0和1.0.31):
#if INTERACTIVE
#I @"..\packages\SQLProvider.1.0.31\lib"
#r "FSharp.Data.SqlProvider.dll"
#I @"..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net46"
#r "System.Data.SQLite.dll"
#I @"..\packages\System.Data.SQLite.Linq.1.0.102.0\lib\net46"
#r "System.Data.SQLite.Linq.dll"
#endif
open System
open FSharp.Data.Sql
//open System.Data.SQLite
//open System.Data.SQLite.Linq
[<Literal>]
let connectionString = "Data Source="+ @"C:\tmp\databaseFile.db3"
[<Literal>]
let resolutionPath = __SOURCE_DIRECTORY__ + @"..\..\packages\System.Data.SQLite.Core.1.0.102.0\lib\net46"
type sql = SqlDataProvider<
Common.DatabaseProviderTypes.SQLITE,
connectionString,
ResolutionPath = resolutionPath,
CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>
let ctx = sql.GetDataContext()
let table2 = ctx.Main.Table2 //DateTime
let table3 = ctx.Main.Table3 //Text
这可能与此issue #196有关。