Closed houdelou closed 2 years ago
@houdelou thanks for the report, could you add "nuget System.Data.SqlClient" to your paket.dependencies file, generate the scripts again, and reference that package before referencing FSharp.Data.SqlClient one?
Here is a very crude script referencing through nuget, but you can replace it with #load statements for the same packagess using paket as well, note that somehow, it is needed to evaluate importing System.Data.SqlClient, so I've put ;;
to force this evaluation:
#r "nuget: System.Data.SqlClient";;
#r "nuget: FSharp.Data.SqlClient"
open System.Data.SqlClient
let [<Literal>] cn = "Server=server;Database=dbname;User Id=user;Password=password;"
type Q = FSharp.Data.SqlCommandProvider< "select * from sys.tables", cn>
let cnx = new SqlConnection(cn)
cnx.Open()
let q = Q(cnx)
let results = q.Execute() |> Seq.toArray
printfn $"hello %A{results}"
Please let me know if this helps.
@smoothdeveloper Thank you for your help. I copied your code into a script file and I still get the same error message. Interesting approach though with the ";;". Are you also using .NET 6 ? I think I could try with other framework versions. .NET 6 is recent so maybe there is not enough dev using it yet ? I'll try to create a new project to see if it might work. Thanks again.
Is it possible that the project references System.Data.SqlClient instead of its successor Microsoft.Data.SqlClient ? Can it be the problem I'm having ?
@houdelou, I'm not reproducing using my sample script in VS 2022 or from dotnet fsi
command line, both works ok.
I'd suggest you first try to make use of a plain System.Data.SqlServer ado.net provider in your environment, to make sure we have a base plate which works, disregarding this library.
Regarding Microsoft.Data.SqlClient, it is not supported in this library for now, but there are discussions: #374 about it.
@smoothdeveloper Ok now it seems to be working with ";;" at the end of the line. I did a couple of tests and finally it worked when I restarted the interpreter. Thanks ! Problem solved
Issue Summary
I'm trying to execute a query from F# script file and I get this error message. Tried also to install package with Paket but it does not change anything. I'm fairly new to F#.
To Reproduce
Steps to reproduce the behavior:
Create a new .NET 6 web F# web application in Visual Studio. Add a script .fsx file Install FSharp.Data.SqlClient Use "dotnet paket generate-load-scripts" to generate a dependency load file. Add a reference to the load file Do a basic query. Select All and right-click "Execute In Interactive"
Error
The type provider 'FSharp.Data.SqlCommandProvider' reported an error: System.Data.SqlClient is not supported on this platform
Expected behavior
Expect to see the query result in the output window.