具有多个(数百个)数据库连接的Win App的最佳架构 [英] Best Architecture for Win App with Multiple (hundreds) Database Connections

查看:67
本文介绍了具有多个(数百个)数据库连接的Win App的最佳架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找一些见解,经验和建议。


使用Visual C ++ 6.0,SQL Server 2005/2008用于传统的Windows应用程序 - 这暂时无法改变所以请不要告诉我,"使用.NET"。 - 是的,我明白了。 :)


考虑到我们有一个使用ADO连接到SQL Server数据库的多线程应用程序。 可能有数百个工作线程需要连接到数据库并执行查询。


  1. 让每个线程创建自己的连接或传入更好指向现有连接的指针?
  2. 如果每个线程更好地创建自己的连接,是否有可能产生数百个同时连接的潜在问题?

 

解决方案

不要创建空闲连接。空闲连接会占用服务器端资源,并可能会降低服务器速度。您可能不会有数百个CPU同时实际使用数百个连接 。当实际的
需要进行数据库工作时打开连接,并在读完/写入数据后立即关闭它。这将返回连接池的连接。 


Looking for some insight, experience, and suggestions.

Using Visual C++ 6.0, SQL Server 2005/2008 for a traditional Windows App - this cannot change, for now, so please don't tell me, "use .NET" - yeah, I get it. :)

Consider that we have a multithreaded application using ADO to connecto to a SQL Server database.  There could be hundreds of worker threads that need to connect to the database and perform queries.

  1. Is it better to have each thread create its own connection or pass in a pointer to an existing connection?
  2. If it is better for each thread to create its own connection, are there any potential issues with possibly making hundreds of simultaneous connections?

 

解决方案

Do not create idle connections. Idle connections take away server side resources and may slow the server down. You probably won't have hundreds of CPUs to actually use the hundreds of connections at the same time . Open a connection when you actual need to do database work, and close it as soon as you finished reading/writing data. This will return the connection to the connection pool. 


这篇关于具有多个(数百个)数据库连接的Win App的最佳架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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