fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

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

Open BlooDCrescent opened 3 years ago

BlooDCrescent commented 3 years ago

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

[] 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>


5. Build a project
6. 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
Thorium commented 3 years ago

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

BlooDCrescent commented 3 years ago

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?

Kurren123 commented 3 years ago

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>
skamlet commented 3 years ago

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

nodakai commented 9 months ago

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