I was trying FSharp data provider but against the Postgresql using npgsql. And I busted at very first line.
When I am trying to create SqlDataConnection it is throwing error with message the connection string is not correct.
The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Keyword not supported: 'port:5432;database'.
Now, I test connection string and also data using Servicestack.Ormlite. That basically uses IdbConnection. So, connection is all correct. But I don't know why Type Provider is not working.
Here is 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 above code first commented line is not working while with same settings below code is working. That means issue is only with type provider not with connections IMHO.
Do I need to do any other settings.
Please let me know if any other details are required.
UPDATE
After kvb's comment I tried both. Here is updated code with web config.
//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 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 assembly in appconfig. I don't think it will be in 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>
Above both one is commented and another one without which is not commented both is failing with different error. First one is failing with error
The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. error 7001: The specified store provider 'Npgsql' cannot be found in the configuration, or 'Npgsql' is not valid. Unable to find the requested .Net Framework Data Provider. It may not be installed.
and second one is with this error
The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. error 7001: The provider did not return a 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 accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) The network path was not found
I still not understand why it is searching for SQL server.
Please let me know if any further infromation required.