首頁  >  文章  >  後端開發  >  無法連線到 azure PostresSQL 資料庫 - 使用者名稱應採用 <使用者名稱@主機名稱> 格式

無法連線到 azure PostresSQL 資料庫 - 使用者名稱應採用 <使用者名稱@主機名稱> 格式

WBOY
WBOY轉載
2024-02-05 21:51:11805瀏覽

无法连接到 azure PostresSQL 数据库 - 用户名应采用 <用户名@主机名> 格式

問題內容

我無法連接到 golang 應用程式中的 azure postgresql 資料庫

錯誤訊息:

fatal: invalid username specified. please check the username and retry connection. the username should be in <username@hostname> format. (sqlstate 28000))

我的用戶名中沒有@。

我使用 gorm 作為 orm 並像這樣連接

dburl := fmt.sprintf("postgres://%s:%s@%s:5432/%s", dbuser, dbpass, dbhost, dbname)
db, err := gorm.open(postgres.open(dburl), &gorm.config{})

我的變數看起來像這樣

postgres_password="password!"
db_host="some-url-with-dashes.postgres.database.azure.com"
app_port="8080"
postgres_user="postgresuser"
db_name="file"

我的程式碼確實看到了它們並正確創建了 dburl ,如下所示:

postgres://postgresuser:[email&#160;protected]:5432/file

我已嘗試更改使用者名稱和密碼


正確答案


您必須配置參數db_user_namespaceon。不要這樣做。

以上是無法連線到 azure PostresSQL 資料庫 - 使用者名稱應採用 <使用者名稱@主機名稱> 格式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除