Home  >  Article  >  Backend Development  >  Unable to connect to azure PostresSQL database - username should be in the format

Unable to connect to azure PostresSQL database - username should be in the format

WBOY
WBOYforward
2024-02-05 21:51:11805browse

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

Question content

I cannot connect to azure postgresql database in golang application

wrong information:

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

There is no @ in my username.

I use gorm as orm and connect like this

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

My variables look like this

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

My code does see them and creates dburl correctly, like this:

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

I have tried changing the username and password


Correct answer


You must configure the parameters db_user_namespace to on. Do not do this.

The above is the detailed content of Unable to connect to azure PostresSQL database - username should be in the format . For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete