Solved

Should we close _RecordsetPtr ?

Posted on 2007-11-21
9
1,229 Views
Last Modified: 2013-11-20
Hi
I am connecting with the MSSQL server and using the code attached. Whenever I get the RecordsetPtr , should I close like (pRdSet ->Close() ) within the function when done?

I am keeping the "_ConnectionPtr cn;" open globally and accessing the database using local RecordsetPtr  on multiple threads (above 100)
Could you please advice me on this?
Regards
Eugene
btSQL=(_bstr_t)sSQL;

		_RecordsetPtr pRdSet;

		//TRACE(sSQL);TRACE("\n");

		pRdSet = cn->Execute(btSQL,&bcnstr,0);

Open in new window

0
Comment
Question by:shiffin
  • 5
  • 4
9 Comments
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20326367
Yes after the use of recordset function is done, you should also close it.
0
 

Author Comment

by:shiffin
ID: 20327785
Hi
Is it ok if I keep the "_ConnectionPtr cn;"  open always?
After few hours, I start getting exception error when I try to create the recordset. Once the exception starts, its always.
I checked by closing recordset also. Error started coming after few hours.
What must be the issue?
Can I close the _ConnectionPtr recordset failed, and open again? Its it a solution?
The error is normally "unspcified error"
Thanks
Eugene
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20328027
Normally, we dont keep the connection "_ConnectionPtr cn;"  open once everything is done and at the end of the page we close it. And again we open it on the top of the page. So, its like

Opening a connection at the top of the page and closing it at the bottom. This is normal procedure what everyone does. By doing this you dont keep connection pool opened. Hope this helps.

The best way what you do is create a common file where you open you connection and include this file to all pages at the TOP where ever you need, and close it at the end.
0
 

Author Comment

by:shiffin
ID: 20329165
But, opening the ConnectionPtr in all the threads will delay the process. Isn't?
Eugene
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20333338
NO never this happens, Opening a connection pointer takes barely milli seconds but you save keeping a connection pool opened for always. And more you use the application you pool never dies and that can occur into error after some time.
0
 

Author Comment

by:shiffin
ID: 20333774
So,
Do you advice me to open libe below on every thread I open? Even if its more than 500 ?

hr=cn.CreateInstance(__uuidof(Connection));

Eugene
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20333889
Looking at your case, i will suggest you to close and again open the connection when recordset failed untill then keep it opened for all. this will work good.
0
 

Author Comment

by:shiffin
ID: 20334051
Great!! This is what I thought of doing. I will check for the record set failure and when it fails, I will close the connection pointer and open it again.
Thanks
Eugene
0
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 500 total points
ID: 20334069
Right, that is the only way to efficiently handle this situation, as there are above 500 threads and we dont want to make one connection pool for each thread. Please go ahead, this will get the solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
Whole sheet autoscrub still needed 19 48
modThree challenge 4 76
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 232
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now