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
581 stars 146 forks source link

Invalid attempt to Read when reader is closed #569

Closed enkerr closed 6 years ago

enkerr commented 6 years ago

I posted this on StackExchange and no one responded with any ideas.

I am just in the process of migrating an F# project from Windows over to Linux Mint (19) and MySQL and Mono (ver 5.10.1.47). I am copying the example text on the MySQL Provider page. I worked through a few errors.

let [<Literal>] connString = @"Server=localhost;Database=PriceData;User=root;Password=-----;SslMode=none"              
let [<Literal>] connexStringName = "DefaultConnectionString"            
let [<Literal>] dbVendor    = Common.DatabaseProviderTypes.MYSQL
let [<Literal>] resPath = __SOURCE_DIRECTORY__ + @"/../../../Simulations 2018-07-29/packages/MySqlConnector.0.43.0/lib/net45"
let [<Literal>] indivAmount = 1000
let [<Literal>] useOptTypes = true

But now I'm stuck at:

type SQL = SqlDataProvider< dbVendor,
                            connString,
                            ResolutionPath = resPath,
                            IndividualsAmount = indivAmount,
                            UseOptionTypes = useOptTypes
                            Owner = "HR" >  ///"PriceData">

Which gives the error:

The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Invalid attempt to Read when reader is closed.

I can't find any discussion online about this error that seems relevant to F# or Type Providers. Any ideas? Thanks.

Thorium commented 6 years ago

I have used the example with Ubuntu & Mono and it did work. (I think it was older version of MySqlConnector though. Maybe they have changed the connection handling.)

SQLProvider usually just exposes the underlying error of the database driver to the user.

But as this comes from the initial step, this can be also a problem with the way SQLProvider queries the initial tables/columns.

Are you compiling to .NET Core/.NET Standard or Mono (Full .NET framework)?

piaste commented 6 years ago

I occasionally get a similar error with other vendors, about the underlying connection being closed. But it's always temporary and restarting the editor fixes it. I'm guessing that's not the case for you?

Do you get the same error if you try using the provider with a local, trivial database (just one simple table)?

On Wed, Aug 22, 2018, 12:51 Tuomas Hietanen notifications@github.com wrote:

I have used the example with Ubuntu & Mono and it did work. (I think it was older version of MySqlConnector though. Maybe they have changed the connection handling.)

SQLProvider usually just exposes the underlying error of the database driver to the user.

But as this comes from the initial step, this can be also a problem with the way SQLProvider queries the initial tables/columns.

Are you compiling to .NET Core/.NET Standard or Mono (Full .NET framework)?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fsprojects/SQLProvider/issues/569#issuecomment-414992270, or mute the thread https://github.com/notifications/unsubscribe-auth/ALtja7ctfjcAl8ceu-ND02DDbCl30p3hks5uTTelgaJpZM4WHM5d .

enkerr commented 6 years ago

Thanks for the suggestions. Locally here it's time to go in to work in the morning. I'll come back and try some things this evening. Thanks again.

PS Oh I think I can answer one of the questions: I've never tried to do anything with .NET Core. My project originated in Windows and Visual Studio 2 or 3 years ago, before there was .NET Core. So I assume I must be just in Mono/Full .NET (I don't know how to check that). But I get the same error about Reader if I open the project now in MonoDevelop or VS Code + Ionide.

enkerr commented 6 years ago

Ok so I rebooted. I created a new database in MySQL with a single table with a single column, with no data. I try to connect to that table with the type provider syntax and the error is the same.

I don't have the slightest idea of anything to do here. I work in finance, not IT. I guess I could rewrite my project to use SQL queries directly without type providers. Which may be a lot more robust. Or maybe it wont?: My inclination now is to leave F# (it was fun for a while) and go to something widely adopted and supported. Probably python.

Thorium commented 6 years ago

If you already know SQL and non-IT background I would recommend https://github.com/rspeele/Rezoom.SQL rather than SQLProvider, as there you can write your queries with SQL, while with SQLProvider you'd have to learn the LINQ-syntax. However, I would like to know what is the connection problem anyway as other users don't seem to face it.

edit: Rezoom is MySQL compatible while FSharp.Data.SqlClient is not.

enkerr commented 6 years ago

Thanks for the suggestions. I'll keep at this issue and try to make progress. I think I generally get the idea that the type provider is not failing, but rather is passing through a database error. I'll try fooling around with the two different dll choices for MySQL, switching them, and with unloading and reloading my packages.

(My pacing is slow because this is on the side of regular job and family. And I redirected efforts this weekend to migrating another copy to Windows again on another extra machine just to get my project back to life. (The original motivation for the move to Linux was the death of my primary hard disk with Windows, and trying Linux for a change. So now I have Linux and Windows drive side by side.) And I can also try the non-type provider SQL route in Linux.)

enkerr commented 6 years ago

Apologies again for my slow pace, but today I got a chance to fool around with the Mono version again. I fooled around a bit with the two possible dlls (MySql.Data and MySqlConnector), and the error persisted. Then I went to nuget and searched TypeProvider for any package that looked like it had anything to do with SQL--and installed all of them. Now the error is gone!

(I now have: F# Core, F# Data, Data.SqlClient, Data.TypeProviders, MySql.Data, MySqlConnector, SQLConnector, SQLProvider, SQLProvider.Signed, System.Buffers, .Memory, .Runtime.CompilerServices.Unsafe, .InteropServices.RuntimeInformation, .Threading, .Threading.Tasks, .Threading.Tasks.Extensions.)

I got 3 or 4 of those today (not sure exactly which). And well at least the error is gone (I still have to try a full run after importing some other edits.)

Thanks for the comments and the patience keeping this issue open. Please feel free to close it.

Thorium commented 6 years ago

You probably do need a reference to System.Data and depending on provider, e.g. MySql, you probably need MySql.Data/MySqlConnector and their NuGet package dependencies which means usually some threading libraries.

You probably don't need FSharp.Data, FSharp.Data.SqlClient, FSharp.Data.TypeProviders and SQLProvider.Signed.