gpt4 book ai didi

asp.net - 如何让 Npgsql 连接到 Postgresql 9.5

转载 作者:太空宇宙 更新时间:2023-11-04 12:38:39 26 4
gpt4 key购买 nike

我有一台 Debian Jessie (i386) 机器,带有 mono-complete、mono-xsp 和 postgresql-9.5(来自 http://apt.postgresql.org/)

我有一个简单的 gridview hello,world 样式页面。以下是 Web.config 的摘录:

<compilation debug="true">
<assemblies>
<add assembly="Npgsql, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"/>
</assemblies>
</compilation>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
support="FF"
description ="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<system.web>
<customErrors mode="Off"/>
<trace enabled="true" localOnly="false" pageOutput="true" requestLimit="100" traceMode="SortByTime" />
</system.web>
<connectionStrings>
<add name="SqlDataSource1" connectionString="Server=127.0.0.1,5432;Database=test;User ID=user;Password=password;" providerName="Npgsql"/>
</connectionStrings>

(在流水线中将 Version 更改为“4.0.0.0”没有任何区别)

我得到以下异常:

System.IO.IOException

Connection lost

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): Mono.Data.Tds.

Exception stack trace: at Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacketHeader () [0x00000] in :0

at Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacket () [0x00000] in :0

at Mono.Data.Tds.Protocol.TdsComm.GetByte () [0x00000] in :0

at Mono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x00000] in :0

at Mono.Data.Tds.Protocol.Tds.NextResult () [0x00000] in :0

at Mono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00000] in :0

postgresql 日志显示如下:

[unknown]@[unknown] LOG: invalid length of startup packet

有人知道我应该从哪里开始寻找问题吗?

最佳答案

解决了。事实证明我省略了 asp:SqlDataSource 标记上的 ProviderName 属性。

正确的 asp:SqlDataSource 标记 (4.0) 如下所示:

<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:ConnStr2 %>" ProviderName="Npgsql" runat="server" SelectCommand="select * from test"></asp:SqlDataSource>

相关的 Web.config 条目:

....
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
support="FF"
description ="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
...
<connectionStrings>
<add name="ConnStr2" connectionString="Server=127.0.0.1;Database=database;User ID=user;Password=password;" providerName="Npgsql"/>

关于asp.net - 如何让 Npgsql 连接到 Postgresql 9.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40821171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com