我们可以使用单个数据库连接从多个线程中同时执行多个数据库选择语句吗? [英] Can we use single database connection to execute multiple database select statements simultaneously from multiple threads?

查看:349
本文介绍了我们可以使用单个数据库连接从多个线程中同时执行多个数据库选择语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用来自多个线程的单个数据库连接来同时读取MS SQL Server中的(或仅执行select语句).是否可以从不同的线程中同时执行所有这些select语句.

I want to use single database connection from multiple threads to read (or to execute only select statements) in MS SQL Server in simultaneously. Is it possible to execute all these select statements in simultaneously from different threads.

我正在Linux环境中使用C ++的MS SQL Server.我需要创建数据库连接池以分别进行读写.所以我想知道是否有可能在只读线程之间共享相同的连接.

I m using MS SQL Server from C++ in Linux environment. I need to create Database connection pools for reading and writing separately. So i want to know is there a possibility of sharing a same connection between threads to read only.

select语句可能返回多行(多于一行或结果集).这会成为问题吗?

The select statements may return multiple rows (more than one row or result set). Will this be a problem?

推荐答案

不要在线程之间使用相同的连接.每个连接只能执行一个命令.为每个线程创建一个连接.我建议创建一个帮助器类,以使您更轻松.

Don't use the same connection across threads. Only one command can be executed per connection. Create a connection for each thread. I'd suggest making a helper class to make this easier for you.

这篇关于我们可以使用单个数据库连接从多个线程中同时执行多个数据库选择语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆