gorm v1.25.1
dsn := "root:xxx@tcp(127.0.0.1:3306)/xxx?charset=utf8mb4&parseTime=True&loc=Local"
gormDb, err := gorm.Open(gormMySQL.Open(dsn))
writeConn := gormDb.WriteDB
_, err := writeConn.Raw("sql clause").Rows
when I execute writeConn.Raw("sql clause").Rows multiple times, then I will occur Error 1040: Too many connections , but If I change to below, then this error is disappear:
dsn := "root:xxx@tcp(127.0.0.1:3306)/xxx?charset=utf8mb4&parseTime=True&loc=Local"
gormDb, err := gorm.Open(gormMySQL.Open(dsn))
writeConn := gormDb.WriteDB
tx := db.Begin()
defer func() {
tx.Commit()
}()
_, err := tx.Raw("sql clause").Rows
I want to know why use writeConn.Raw("sql clause").Rows directly cause this error? does it open a new connection to mysql db and how can I close this single connection ?
Comment From: github-actions[bot]
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 30 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 ✨