wsarecv:golang中的远程主机强行关闭现有连接

时间:2017-05-23 19:38:28

标签: postgresql go

我正在使用golang和postgre构建应用程序。 当我连接postgre服务器时,我收到错误read tcp 127.0.0.1:56377->127.0.0.1:5432: wsarecv: An existing connection was forcibly closed by the remote host。 我的代码如下:

package db

import (
    "log"

    "github.com/jackc/pgx"
    "github.com/unirep/ur-local-web/app/config"
)

var connConfig pgx.ConnConfig

//Open connects to the database
func Open(dbConfig config.DatabaseConnectionParams) {

    if connConfig.Host == "" {

        connConfig = pgx.ConnConfig{
            User:              dbConfig.Username,
            Password:          dbConfig.Password,
            Host:              dbConfig.Host,
            Port:              5432,
            Database:          dbConfig.DatabaseName,
            TLSConfig:         nil,
            UseFallbackTLS:    false,
            FallbackTLSConfig: nil,
        }
    }
}

//Connect returns a connection to the database
func Connect() *pgx.Conn {
    conn, err := pgx.Connect(connConfig)//Here is error
    if err != nil {
        log.Printf("%T %+v", err, err)
        //os.Exit(1)
    }
    return conn
}

Postgre设置:

PostgreSQL 9.5
Hostname localhost
Port 5432
Username postgres
Password apple

我的操作系统为windows 10

有谁知道这个错误?我该如何解决这个错误?

PS:很少有效。但大多数情况下会发生此错误。

0 个答案:

没有答案