Closed nymbian closed 2 years ago
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question
template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
!!! 怎么解决
我也遇到了,好像密码里有#就会有问题
I have also encountered it. It seems that there will be problems if there is # in the password。And The common special point is that all problems occur in MSSQL
The following is an example code:
host:="sqlserver://sa:E3pl2021#@!@:localhost:1433"
db, err = gorm.Open(sqlserver.Open(host), &gorm.Config{
})
if err != nil {
log.Fatalf("Dbhost: %v, initDB failed:%s", host, err)
return err
}
@cute-angelia 解决方法就是在这个链接外面再套一个"" 比如上面的例子就变成
host:=“\"sqlserver://sa:E3pl2021#@!@:localhost:1433\""
新测有效
When use sqlserver with password "E3pl2021#@!" report error: failed to initialize database, got error parse "sqlserver://sa:E3pl2021": invalid port ":E3pl2021" after host
dsn := "sqlserver://sa:E3pl2021#@!@" + host + ":1433?database=" + database