I tried to use the FSharp data provider, but against Postgresql using npgsql. And I went broke on the first line.
When I try to create a SqlDataConnection, it throws an error with a message that the connection string is incorrect.
A provider of type 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Keyword not supported:' port: 5432; database '.
Now I am testing the connection string as well as the data using Servicestack.Ormlite. It mainly uses IdbConnection. So the connection is all right. But I do not know why the Type Provider is not working.
Here is the code.
//type dbSchema = SqlDataConnection<ConnectionString = "Server=localhost;Port=5432; Database=TestDB;User Id=postgres;Password=g00gle*92;" > [<CLIMutable>] type Person = { ID : int; FirstName : string; LastName : string } [<EntryPoint>] let main args = let dbFactory = OrmLiteConnectionFactory ( "Server=localhost;Port=5432; Database=TestDB;User Id=postgres;Password=*****;", PostgreSqlDialect.Provider) use dbConnection = dbFactory.OpenDbConnection() Console.WriteLine dbConnection.State let persons = dbConnection.Select<Person>() persons.ForEach(fun p -> Console.WriteLine p.FirstName) Console.Read() |> ignore 0
In the above code, the first line with comments does not work, while the same settings below the code work. This means that the problem is only with the type provider, and not with IMHO connections.
Do I need to make any other settings.
Please let me know if any other details are required.
UPDATE
After kvb comment I tried both. Here is the updated web configuration code.
//type dbSchema = SqlEntityConnection<ConnectionStringName = "TestDB", Provider="Npgsql"> type dbSchema = SqlEntityConnection< ConnectionStringName="TestDB" > [<CLIMutable>] type Person = { ID : int; FirstName : string; LastName : string } [<EntryPoint>] let main args = let dbFactory = OrmLiteConnectionFactory ( "Server=localhost;Port=5432; Database=TestDB;User Id=postgres;Password=*******;", PostgreSqlDialect.Provider) use dbConnection = dbFactory.OpenDbConnection() Console.WriteLine dbConnection.State let persons = dbConnection.Select<Person>() persons.ForEach(fun p -> Console.WriteLine p.FirstName) Console.Read() |> ignore 0
And here is the web config
<system.data> <DbProviderFactories> <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" /> </DbProviderFactories> </system.data> <connectionStrings> <add name="TestDB" connectionString="Server=localhost:5432; Database=TestDB;User Id=postgres;Password=******;" providerName="Npgsql" /> </connectionStrings>
and here is the assembly in appconfig. I donโt think it will be in the GAC, as I added via nuget
<dependentAssembly> <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" /> </dependentAssembly>
Both are commented above, and the other, without which it is not commented, does not work with an error. First error with error
A provider like 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. error 7001: the specified Nvpql store provider cannot be found in the configuration, or 'Npgsql' is not valid. Could not find the requested .Net Framework Data Provider. It cannot be installed.
and the second with this error
A provider like 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. error 7001: the provider did not return the ProviderManifestToken string. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not available. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: named pipe provider, error: 40 - Could not open connection to SQL Server). No network path was found
I still don't understand why it is looking for a SQL server.
Please let me know if further information is required.