当前位置:网站首页>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)
边栏推荐
- Realization of basic function of sequence table
- Dip1000 implicitly tagged with fields
- Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
- Openfeign facile à utiliser
- Sqli labs level 12
- Pclpy projection filter -- projection of point cloud to cylinder
- TCP/IP—传输层
- Minecraft模组服开服
- The source code of the live app. When the verification method is mailbox verification, the verification code is automatically sent to the entered mailbox
- Minecraft群组服开服
猜你喜欢

What is SQL injection

Openfeign facile à utiliser

Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)

Openfeign is easy to use

Sqli labs level 1

Flex layout

OpenShift 容器平台社区版 OKD 4.10.0部署

Valin cable: BI application promotes enterprise digital transformation

Realization of basic function of sequence table
![[blackmail virus data recovery] suffix Rook3 blackmail virus](/img/46/debc848d17767d021f3f41924cccfe.jpg)
[blackmail virus data recovery] suffix Rook3 blackmail virus
随机推荐
c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)
Rotating linked list (illustration)
Zipkin is easy to use
First week of JS study
Benefits of ufcs of D
Causes of laptop jam
【无标题】
Learning C
Realization of basic function of sequence table
使用wireshark抓取Tcp三次握手
Development of digital collection trading website development of metauniverse digital collection
Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
Deep understanding of JVM
Minecraft插件服开服
Makefile Fundamentals
Introduction to anti interception technology of wechat domain name
路由基础—动态路由
When a custom exception encounters reflection
Realize bidirectional linked list (with puppet node)
Googlenet network explanation and model building