当前位置:网站首页>commands out of sync. did you run multiple statements at once
commands out of sync. did you run multiple statements at once
2022-07-02 08:41:00 【Tutu is a cat】
problem
The database connection error is caused after several insert operations , Throw an error
commands out of sync. did you run multiple statements at once
reason
- First, the normal insertion operation can eliminate the problem of connection parameters
- The check found that the database was inserted many times, resulting in open Too many database connections .

solve
Define global database connections , That is, the same connection is used multiple times
Define a public variable
var (
DB *gorm.DB
)
Define a function to establish a connection
func GetDB() (*gorm.DB,error) {
dsn := "root:[email protected](127.0.0.1:3306)/trs_hycloud_igi?charset=utf8&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
})
if err != nil {
return nil, err
}
return db, err
}
Call the connected function in the main function and assign values to the defined public variables
func main() {
service.DB,_= service.GetDB()
}
Other database operations can directly use public variable operations
db := DB
db.Create(&reply)
边栏推荐
猜你喜欢

File upload Labs

链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)

File upload and download performance test based on the locust framework

Carsim 学习心得-粗略翻译1

使用wireshark抓取Tcp三次握手

When a custom exception encounters reflection

Smart agriculture solutions smart agriculture system development
![[blackmail virus data recovery] suffix Hydra blackmail virus](/img/27/f44334cf98229d0f8b33c70a878ca8.jpg)
[blackmail virus data recovery] suffix Hydra blackmail virus

Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away

c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)
随机推荐
Benefits of ufcs of D
Method recursion (Fibonacci sequence, frog jumping steps, tower of Hanoi problem)
ICMP Protocol
Jumping | Blue Bridge Cup
Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
整理秒杀系统的面试必备!!!
sqli-labs第12关
Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
Deep understanding of JVM
Sqli labs level 12
Solid principle: explanation and examples
[untitled]
顺序表基本功能函数的实现
Minecraft插件服开服
Sqli labs (post type injection)
Qunhui NAS configuring iSCSI storage
Web security -- core defense mechanism
How to uninstall SQL Server cleanly
Sqli labs level 1
Programming ape learning English - imperative programming