C# 连接 postgres失败

小程序完成了,要发布到客户的服务器上:

我的测试机:win10  64             数据库:PG9.6.5     64

客户服务器:win7    32             数据库:PG9.6.12   32

---

发布完总是提示  failed to establish a connection to ……

连接串  Server=localhost;Port=5432;User Id=postgres;Password=123; Database=postgres

百思不得其解: pg_hba   也授权了   host        all         all          127.0.0.1/24     trust

但是我发现: Server=127.0.0.1;Port=5432;User Id=postgres;Password=123; Database=postgres

直接用IP可以!!!!!!

what?????????????

用客户服务程序连接我的机器没有问题,我的机器连接服务器数据库也没有问题,

还就是服务器程序连接服务器的数据库不成!

最后一高人告诉我:看看服务器上的  localhost  是什么????

晕,我不得不承认我是小白!

最后在服务的  system32drivershosts  里看到    #  127.0.0.1  localhost  

被注释掉了!

去掉注释,一切OK!

原文地址:https://www.cnblogs.com/ssqhan/p/10568231.html