使用Npgsql 3.2.3 for .Net V4框架我在我的C#程序中遇到了一个奇怪的问题。 附加到本地PostGres数据库9.5(整理EN) 并使用ST_INTERSECTS执行select,如下所示:
cmd.CommandText = "select count(0) as Total from XXXXXX g
where ST_Intersects(g.geom, ST_GeomFromText('LINESTRING (92416.93536738542 452000.74351332453,92426.189685434016 451997.21004643326)')) "
(XXXX是表名)
try
{
using (Npgsql.NpgsqlDataReader _reader = cmd.ExecuteReader())
{
if (_reader.Read())
{
strResultaat = _reader["AANTAL"].ToString();
}
}
}
我得到了适当的回应。当在代码中执行相同的查询到其他PostGres数据库(整理NL)时,我得到错误:
Message: "Exception while reading from stream"
RemoteStackTrace: null
Source: "Npgsql"
ErrorCode: -2147467259
..
StackTrace: " at Npgsql.ReadBuffer.<Ensure>d__27.MoveNext()\r\n---
---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at Npgsql.NpgsqlConnector.<DoReadMessage>d__147.MoveNext()\r\n---
---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()\r\n
at Npgsql.NpgsqlConnector.<ReadMessage>d__146.MoveNext()\r\n---
如果我省略ST_Intersects
where子句(所以只是在同一个表上简单选择count(0)),我会在两个数据库上得到适当的响应。
在PgAdmin4
中对其中一个数据库执行此选择会再次为我提供正确的结果。
我错过了什么吗?
更新 将两个数据库的整理/字符集更改为相同和更多测试之后,仍然困惑,添加
CommandTimeout=0;TimeOut=0;Keepalive=0;Pooling=false;
到ConnectionString没有帮助。
这是有效的
select count(0) as Total from vw_bkk g where ST_Intersects(g.GEOM, ST_GeomFromText('LINESTRING (92416.93536738542 452000.74351332453,92426.189685434016 451997.21004643326)'))
但这不会:
select count(0) as Total from vw_bkk g where ST_Intersects(g.GEOM, ST_GeomFromText('POLYGON((92435.107224574778 452020.56550608773, 92436.9042605573 452019.77627840184, 92437.781275783462 452019.33857956366, 92441.100836461876 452017.25236467138, 92441.875609279086 452016.65197891078, 92444.724385195354 452013.95823589037, 92445.367141518756 452013.21823569539, 92447.635655810838 452010.02048358152, 92448.121694875386 452009.1693067447, 92449.722769812055 452005.59043335693, 92450.033413409081 452004.66079012671, 92450.905520578031 452000.8383295628, 92451.0288308483 451999.86594560725, 92451.138455660257 451995.94679288281, 92451.069693859245 451994.96903637191, 92450.412623494063 451991.10380232794, 92450.154432099211 451990.15824789618, 92448.755917402814 451986.49547131034, 92448.318218564644 451985.61845608416, 92446.232003672034 451982.2988954052, 92445.631617911422 451981.524122588, 92442.93787489098 451978.67534667178, 92442.197874696 451978.03259034839, 92439.00012258286 451975.76407605677, 92 438.148945746027 451975.27803699218, 92434.57007235699 451973.676962055, 92433.640429126783 451973.366318458, 92429.8179685644 451972.49421128939, 92428.845584608818 451972.37090101908, 92424.926431882632 451972.26127620705, 92423.94867537175 451972.33003800811, 92420.083441328767 451972.9871083732, 92419.137886896991 451973.24529976805, 92417.272146293253 451973.85458677879, 92408.017828244658 451977.38805367006, 92406.220792262131 451978.17728135595, 92405.343777035974 451978.61498019414, 92402.02421635756 451980.70119508641, 92401.24944354035 451981.301580847, 92398.400667624082 451983.99532386742, 92397.75791130068 451984.73532406241, 92395.4893970086 451987.93307617627, 92395.00335794405 451988.78425301309, 92393.402283007381 451992.36312640086, 92393.091639410355 451993.29276963108, 92392.2195322414 451997.115230195, 92392.096221971136 451998.08761415054, 92391.986597159179 452002.006766875, 92392.055358960191 452002.98452338588, 92392.712429325373 452006.84975742985, 92392.970620720225 452007.7953118616 1, 92394.369135416622 452011.45808844746, 92394.806834254792 452012.33510367363, 92396.8930491474 452015.65466435259, 92397.493434908014 452016.42943716981, 92400.187177928456 452019.278213086, 92400.927178123442 452019.9209694094, 92404.124930236576 452022.189483701, 92404.976107073409 452022.67552276561, 92408.554980462446 452024.27659770282, 92409.484623692653 452024.5872412998, 92413.307084255037 452025.4593484684, 92414.279468210618 452025.58265873871, 92418.1986209368 452025.69228355074, 92419.176377447686 452025.62352174969, 92423.041611490669 452024.96645138459, 92423.987165922445 452024.70825998974, 92425.852906526183 452024.098972979, 92435.107224574778 452020.56550608773))'))
在不同表格的同一数据库中:
不起作用
strSQL=" select count(0) as Total from QS_VW_GEO g where ST_Intersects(g.GEOM, ST_GeomFromText('LINESTRING (92416.93536738542 452000.74351332453,92426.189685434016 451997.21004643326)')) "
有效吗
strSQL=" select count(0) as Total from QS_TB_GEO g where ST_Intersects(g.GEOM, ST_GeomFromText('LINESTRING (92416.93536738542 452000.74351332453,92426.189685434016 451997.21004643326)')) "