当前位置:网站首页>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 06:30:00 【图图是只猫】
问题
数据库在执行几次插入操作后导致数据库连接错误,抛出错误
commands out of sync. did you run multiple statements at once
原因
- 首先正常插入操作可以排除连接参数问题
- 检查发现数据库由于多次插入操作导致此处open了过多的数据库连接。

解决
定义全局的数据库连接,即同一个连接多次使用
定义一个公共的变量
var (
DB *gorm.DB
)
定义一个建立连接的函数
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
}
在主函数中调用建立连接的函数并对定义的公共的变量赋值
func main() {
service.DB,_= service.GetDB()
}
其他数据库操作可直接使用公共变量操作
db := DB
db.Create(&reply)
边栏推荐
- [blackmail virus data recovery] suffix Hydra blackmail virus
- Use the numbers 5, 5, 5, 1 to perform four operations. Each number should be used only once, and the operation result value is required to be 24
- Kubedm deploys kubernetes v1.23.5 cluster
- 双向链表的实现(双向链表与单向链表的简单区别联系和实现)
- sqli-labs(POST类型注入)
- HCIA—数据链路层
- Using C language to realize MySQL true paging
- ARP及ARP欺骗
- How to apply for a secondary domain name?
- One of the reasons for WCF update service reference error
猜你喜欢

HCIA—應用層
![[dynamic planning] p4170: coloring (interval DP)](/img/52/76f8baebb19fe10db91c74fec9a697.jpg)
[dynamic planning] p4170: coloring (interval DP)

Luogu greedy part of the backpack line segment covers the queue to receive water

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

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

Minecraft群组服开服

What is SQL injection

Sqli labs Level 2

STM32 new project (refer to punctual atom)

Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
随机推荐
Luogu greedy part of the backpack line segment covers the queue to receive water
CarSim learning experience - rough translation 1
Simple implementation scheme of transcoding and streaming (I)
链表经典面试题(反转链表,中间节点,倒数第k个节点,合并分割链表,删除重复节点)
Dip1000 implicitly tagged with fields
Deep understanding of JVM
sqli-labs第2关
Web安全--核心防御机制
Using C language to realize MySQL true paging
Tcp/ip - transport layer
[flask] ORM one-to-one relationship
HCIA—應用層
Introduction to anti interception technology of wechat domain name
Force deduction method summary: double pointer
Web security -- Logical ultra vires
Programming ape learning English - imperative programming
Sentinel 简单使用
Sqli labs level 12
Matlab other
k8s入门:Helm 构建 MySQL