保持SQL连接打开迭代多次请求?或关闭的每一步? [英] Keep Sql Connection open for iterating many requests? Or close each step?

查看:244
本文介绍了保持SQL连接打开迭代多次请求?或关闭的每一步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿 - 这是一般到任何操作调用一个SQL服务器或任何需要在一个开放的连接

说我有任何地方从20至1000选择呼叫使在数据中的每个项被循环。对于每一步,我会从SQL选择,在当地一个结构存储数据,然后继续。这不是一个非常昂贵的电话,所以我应该保持连接打开整个循环?或者我应该打开和关闭的每一步?

如何昂贵的运行时打开一个连接?我觉得这是更好地保持连接打开,但想拿到这个正确的反应。

感谢。


解决方案

  

如何昂贵的运行时打开连接


此只考虑CPU的速度和不考虑带宽。

保持开放的连接上的CPU节省,但它阻止能够使用该连接其他请求。因此,它的一个权衡。其很难说什么是正确反应是不知道了很多,但在两种情况下,它似乎是一个是的与公差修修补补,而不是钉标称值

这是说我通常通过保持连接打开SQL工作单元的时间开始,然后将其关闭。

虽然一件事,确实显得有点粗略就是这一行


  

20〜1000,选择通话,使在绕环数据的每个项目。


试着做更多的基于集合运算来代替。

Hey there -- this is general to any operation calling an SQL server, or anything requiring an open connection at that.

Say I have anywhere from 20 to 1000 Select calls to make for each item in data being looped. For each step, I'll select from sql, store data locally in a struct, then proceed. This is not a very expensive call, so should I keep the connection open for the entire loop? Or should I open and close every step?

How expensive in run time is opening a connection? I would think it'd be better to keep the connection open, but would like to get the correct response for this.

Thanks.

解决方案

How expensive in run time is opening a connection

This only considers CPU speed and doesn't consider bandwidth.

Keeping an open connection saves on CPU but it blocks other requests from being able to use that connection. So its a trade off. Its tough to say what the "correct response" is without knowing a lot more, but in either case it seems like one is tinkering with tolerances instead of nailing the nominals

That said I typically start by keeping a connection open for the duration of a unit of SQL work and then close it.

Although one thing that does seem a little sketchy is this line

20 to 1000 Select calls to make for each item in data being looped.

Try and do more set based operations instead.

这篇关于保持SQL连接打开迭代多次请求?或关闭的每一步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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