我的web.config:
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.PostgreSql" />
<add name="Npgsql Data Provider" invariant="Devart.Data.PostgreSql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="OcrCliaCargoEntities" connectionString="metadata=res://*/OcrClia.Cargo.OcrCliaCargoDB.csdl|res://*/OcrClia.Cargo.OcrCliaCargoDB.ssdl|res://*/OcrClia.Cargo.OcrCliaCargoDB.msl;provider=Devart.Data.PostgreSql;provider connection string=user id=postgres;host=10.40.51.202;database=cargo;initial schema=tobackup" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="Devart.Data.PostgreSql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
查询时发生以下错误: 不支持关键字:&#39; host&#39;
参考文献:
<package id="EntityFramework" version="6.1.0" targetFramework="net40" />
<package id="Npgsql" version="2.1.3" targetFramework="net40" />
<package id="Npgsql.EntityFramework" version="2.1.3" targetFramework="net40" />
我的工作机器上安装了试用版:dcpostgresql.exe
有人遇到过这个问题吗?
答案 0 :(得分:0)
According to connectionstrings.com,使用npgsql的主机的正确连接参数是Server
而不是Host
。这模仿了SQL Server的连接字符串格式,它也使用Server
。
所以你的连接字符串应该是:
<add name="OcrCliaCargoEntities" connectionString="metadata=res://*/OcrClia.Cargo.OcrCliaCargoDB.csdl|res://*/OcrClia.Cargo.OcrCliaCargoDB.ssdl|res://*/OcrClia.Cargo.OcrCliaCargoDB.msl;provider=Devart.Data.PostgreSql;provider connection string=user id=postgres;Server=10.40.51.202;database=cargo;initial schema=tobackup" providerName="System.Data.EntityClient" />
/// -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^^^^^^