在使用gorm连接sql server数据库时,如果密码中包含“@”符号,可能会导致连接失败。
为了解决密码包含“@”符号导致的连接问题,需要采用分列参数建立连接字符串,而不是将参数写在一起。
示例代码如下:
connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%d;database=%s", server, user, password, port, database) db, err := gorm.Open("mssql", connectionString)
其中,
使用这种方法,可以避免因密码中包含“@”符号而导致的连接问题。