无法从Go应用程序与Apache Age服务器建立连接。

huangapple go评论86阅读模式
英文:

Unable to establish a connection to Apache Age server from Go application

问题

我正在开发一个Go应用程序,需要连接到一个Apache Age服务器,但是在尝试建立连接时遇到了问题。
当我运行我的Go应用程序并尝试连接到Apache Age服务器时,我收到了一个“无法连接到Apache Age服务器”的错误。

我正在使用以下代码从我的Go应用程序建立连接:

db, err := sql.Open("age", "host=localhost port=5432 dbname=mydb user=myuser password=mypassword")
if err != nil {
    panic(err)
}
defer db.Close()

我期望这段代码能够成功地连接到Apache Age服务器,从而允许我执行数据库操作。

然而,当运行代码时,我收到了一个“无法连接到Apache Age服务器”的错误。我已确认Apache Age服务器正在指定的主机和端口上运行并接受连接。

英文:

I'm working on a Go application that needs to connect to an Apache Age server, but I'm encountering an issue when trying to establish the connection.
When I run my Go application and attempt to connect to the Apache Age server, I'm getting a 'cannot connect to Apache Age server' error.

I'm using the following code to establish the connection from my Go application:

db, err := sql.Open("age", "host=localhost port=5432 dbname=mydb
user=myuser password=mypassword")if err != nil {
    panic(err)
}
defer db.Close()

I expected the code to successfully establish a connection to the Apache Age server, allowing me to perform database operations.

However, when running the code, I'm getting a 'cannot connect to Apache Age server' error. I have confirmed that the Apache Age server is running and accepting connections on the specified host and port.

答案1

得分: 1

package main

import (
	_ "github.com/lib/pq"
)

var dsn string = "host=127.0.0.1 port=5432 dbname=postgres user=postgres password=agens sslmode=disable"

func main() {
	db, err := sql.Open("postgres", dsn)
	if err != nil {
		panic(err)
	}

	// ...
}

更多信息请参考官方示例

英文:
package main

import (
	_ "github.com/lib/pq"
)

var dsn string = "host=127.0.0.1 port=5432 dbname=postgres user=postgres password=agens sslmode=disable"

func main() {
	db, err := sql.Open("postgres", dsn)
	if err != nil {
		panic(err)
	}

	// ...
}

See the official sample for more information.

答案2

得分: 0

请检查PostgreSQL驱动程序。GO通常使用像pqpgx这样的PostgreSQL驱动程序来连接Apache AGE服务器。请确保在您的代码中导入了正确的驱动程序。

英文:

Check the PostgreSQL driver. GO typically use a PostgreSQL driver like pq or pgx to connect to an Apache AGE server. Please ensure you have imported the correct driver in your code.

huangapple
  • 本文由 发表于 2023年5月1日 20:07:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76146801.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定