성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Get Started with Milvus Vector DB i...
[정성태] cyberark/PipeViewer - A tool that...
[정성태] WinForms in a 64-Bit world – our st...
[정성태] 예제에서 SELECT_SQL도 내부적으로는 SqlCommand/...
[victor] SELECT_LINQ SELECT_SQL 같은 쿼리인...
[victor] 답변 갑사합니다. 예외(Exception)가 났습니다. ...
[정성태] 일단, 위의 방식대로 하면 예외(Exception) 없이 잘 동...
[정성태] Windows 10 (버전 1809)에 이런 기능이 ^^ 추가되...
[정성태] pde windbg extension ; https://lea...
[정성태] // GetEnumerator extensions for Ran...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C# - SqlConnection의 최소 Pooling 수를 초과한 DB 연결은 언제 해제될까요?</h1> <p> 그냥 간단하게 테스트를 해보면 알 수 있는 문제입니다.<br /> <br /> 일례로 다음과 같이 연결 문자열을 설정하면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > <span style='color: blue; font-weight: bold'>Min Pool Size=5;</span> Persist Security Info=True;Initial Catalog=TestDB; Server=127.0.0.1; ...[생략]... </pre> <br /> 최소 5개의 DB 연결을, 쓰든 안 쓰든 유지하게 됩니다. 실제로 5개의 연결이 유지되고 있는지 확인하고 싶다면, 간단하게 "Performance Monitor" 도구를 실행해, "Performance" / "Monitoring Tools" / "Performance Monitor" 노드로 이동 후, 상단의 "+" 버튼을 눌러 "Add Coutners" 창을 띄웁니다. 그럼 다음과 같이 ".NET Data Provider for SqlServer" 범주를 찾아, <br /> <br /> <img alt='check_pooled_connections_1.png' src='/SysWebRes/bbs/check_pooled_connections_1.png' /><br /> <br /> 그 영역에 포함된 "NumberOfPooledConnections" 항목을 선택하면,<br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='check_pooled_connections_2.png' src='/SysWebRes/bbs/check_pooled_connections_2.png' /><br /> <br /> 위의 화면에서 보는 것처럼, "SqlConnection" 개체를 사용하는 응용 프로그램 목록이 왼쪽 하단에 "Instances of selected object" 목록에 뜹니다. 대괄호 안에 있는 것이 PID이기 때문에, 적절하게 여러분이 테스트하는 응용 프로그램의 것을 선택하면,<br /> <br /> <img alt='check_pooled_connections_3.png' src='/SysWebRes/bbs/check_pooled_connections_3.png' /><br /> <br /> 위의 화면처럼 현재의 연결 개체 수를 "Last"라는 항목으로 보여줍니다. 위의 경우 5를 보여주고 있는데, 이 글에서 테스트하고 있는 연결 문자열의 "Min Pool Size" 값을 5로 했기 때문에 예상한 그대로 화면에 출력되고 있는 것이 맞습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 자, 그럼 테스트를 위해 간단하게 다음과 같은 식의 웹 페이지를 만들고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > using System; using System.Configuration; using System.Data.SqlClient; using System.Threading.Tasks; namespace WebSiteTest { public partial class PoolCountTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int count = 0; string cnt = Request.QueryString["n"]; if (string.IsNullOrEmpty(cnt) == false) { count = int.Parse(cnt); } for (int i = 0; i < count; i++) { Task.Factory.StartNew(() => { DoQuery(); }); } } private void DoQuery() { string connectionString = "Min Pool Size=5; Persist Security Info=True;Initial Catalog=TestDB; Server=127.0.0.1; ...[생략]..."; SqlConnection sqlConnection = new SqlConnection(connectionString); { sqlConnection.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = sqlConnection; cmd.CommandText = "SELECT * FROM mytable; <span style='color: blue; font-weight: bold'>WAITFOR DELAY '000:00:10'</span>"; cmd.ExecuteNonQuery(); sqlConnection.Close(); } } } } </pre> <br /> "/PoolCountTest.aspx?<span style='color: blue; font-weight: bold'>n=10</span>"으로 요청을 보내면, 5개의 최소 연결을 초과하기 때문에 그 순간부터 이렇게 10개로 늘어나게 됩니다. <br /> <br /> <img onclick='toggle_img(this)' class='imgView' alt='check_pooled_connections_4.png' src='/SysWebRes/bbs/check_pooled_connections_4.png' /><br /> <br /> 이제 남은 것은, 다시 5개로 떨어지길 기대하면 되는데요, 대략 4분여 정도에 다시 5로 내려가는 것을 볼 수 있습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 비록 테스트를 통해 결국 알아내긴 했지만, 이 시간을 그다지 신뢰해서는 안 됩니다. 왜냐하면 내부 설정은 얼마든지 버전에 따라 달라질 수 있고, 이 결과는 .NET Framework BCL의 System.Data.SqlClient에만 해당할 수 있다는 것도 간과하시면 안 됩니다.<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
2001
(왼쪽의 숫자를 입력해야 합니다.)