SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

Unclear exception in sqlite type provider in .net core 3.1 project

Open BlooDCrescent opened this issue 5 years ago • 5 comments
trafficstars

Describe the bug In a netcoreapp3.1 project creating a SqlTypeProvider with provider type SQLITE yields a vague exception

To Reproduce Steps to reproduce the behavior:

  1. Create a new console app project, target .net core 3.1
  2. Create an empty database
  3. Install SQLProvider and Microsoft.Data.Sqlite nuget packages
  4. Type the following code in Program.fs file:
open FSharp.Data.Sql

[<Literal>]
let connectionString =
            "Data Source=" + 
            __SOURCE_DIRECTORY__ + @"\BarDb.db;" + 
            "Version=3;foreign keys=true"

type sql = SqlDataProvider<
                        Common.DatabaseProviderTypes.SQLITE,
                        connectionString,
                        SQLiteLibrary = Common.SQLiteLibrary.MicrosoftDataSqlite,
                        CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>
  1. Build a project
  2. See error

Expected behavior Code compiles without errors

Actual behavior An error is displayed:

Error FS3033 The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Exception has been thrown by the target of an invocation.

Desktop

  • OS: Windows 10 version 1909
  • .NET SDK: .net core 3.1.301

BlooDCrescent avatar Jul 06 '20 22:07 BlooDCrescent

I think you need to add ResolutionPath static parameter and put there the correct libraries (probably x86 versions if you run in Visual Studio).

Thorium avatar Jul 07 '20 17:07 Thorium

I think you need to add ResolutionPath static parameter and put there the correct libraries (probably x86 versions if you run in Visual Studio).

Which ones? I googled e_sqlite3.dll but couldn't understand where I can acquire one and which version. Also, why x86?

BlooDCrescent avatar Jul 07 '20 17:07 BlooDCrescent

I am also having this issue. I put System.Data.SQLite.dll in my source directory and I get an unclear "The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Exception has been thrown by the target of an invocation.". My code:

[<Literal>]
let ConnectionString = "Data Source=" + __SOURCE_DIRECTORY__ + @"/../transactions.db;"
type Database = 
    SqlDataProvider<
        Common.DatabaseProviderTypes.SQLITE,
        ConnectionString = ConnectionString,
        ResolutionPath = __SOURCE_DIRECTORY__,
        CaseSensitivityChange = Common.CaseSensitivityChange.ORIGINAL>

Kurren123 avatar Sep 28 '20 10:09 Kurren123

I have the same issue, did you find any solutions regarding this mater?

skamlet avatar Jan 29 '21 15:01 skamlet

Cross-posted from https://www.reddit.com/r/fsharp/comments/16bq1da/sqlitesqlprovider_on_arm64_linux_mac/

I could successfully call raw SQL API from Microsoft.Data.Sqlite but when I wrote

type sql = SqlDataProvider<
    DatabaseVendor = DatabaseProviderTypes.SQLITE,
    SQLiteLibrary = SQLiteLibrary.MicrosoftDataSqlite,
    ResolutionPath = "symlink/to/dir/containing/SQLitePCLRaw.core.dll",
    ...snip...

I got this error

error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: You need to call SQLitePCL.raw.SetProvider(). If you are using a bundle package, this is done by calling SQLitePCL.Batteries.Init()

Microsoft.Data.Sqlite seems to call .Init() as required by SQLitePCL.raw but maybe the type provider evaluator (?) runs before that? Could anyone provide insights into what might be causing this issue?

.NET 7 on M1 Mac

nodakai avatar Sep 08 '23 05:09 nodakai