Click to See Complete Forum and Search --> : Disconnected Recordsets in ADO


nkishore
August 15th, 1999, 03:08 AM
Hi,
I am developing MTS components in VC++. The component methods return recordsets. For that I am opening a connection to database and then opening the recordset against the connection object i created. Once the recordset has been opened, I would like to close the connection object and set the connection pointer to null before returning from the methods. Basically I want to return a disconnected recorset. But VC++ doesn't allow me close the connection object. I have to keep the connection object till my client uses the recordset. Incase of VB I am able to close the connection object and return the recordset. Why this is not possible in VC++.

Can anyone throw light on creating Disconnected recordsets in VC++, their uses ( advantages).??

Thanks & regards

Kishore

Bob Place
August 15th, 1999, 07:43 AM
Take a look at the atricle ADO is AOK Part 2 (here at codeguru). the sample code shows you how.

Bob

nkishore
August 16th, 1999, 07:58 AM
Hi
Thanks for the reply.. The reason why i posted this question is " I am able to close the connection object successfully and return the recordset( disconnected) from a method without doing any extra in VB" . But in case of VC++, i need to call "put-activerefconnection and do the remaining to return a disconnected recordset"? Why is that? How VB is able to do that??

I hope you got point?

Thanks & Regards
Kishore

Bob Place
August 16th, 1999, 08:21 AM
I am not sure of the VB code needed to create a disconnected recordset, but below is what I use in a method to create and send back a disconnected recordset (actually, the IDsiapatch of the recordset). So while I can not answer why you have to set the activeconnection in VC and not in VB.

YOu may want to take a look at the article here called (something like) "creating disconnected recordsets in VC++" It is in the Database/ADO section I think. It started me on my trip. Though, the sample in that article returns a Recordset object, where I have modified it to return the IDispatch of the recordset. Take a look at that and this code below.

It may be that VB takes care of alot of this for you. (My VB skills are slimm at best).


_variant_t vHolder;
m_Recordset.CreateInstance(__uuidof(Recordset));
//Client side cursor is required for disconnected recordsets
m_Recordset->CursorLocation = adUseClient;
m_Recordset2->Open( SQL,m_Connection2.GetInterfacePtr(),adOpenKeyset, adLockOptimistic, -1);

// Disconnect the recordset
m_Recordset2->PutRefActiveConnection(NULL);

vHolder = static_cast<IDispatch*>(m_Recordset2);
*Result = vHolder.Detach();

nkishore
August 17th, 1999, 01:24 AM
Hi
Thanks for the reply. I also got the same doubt.. Whatever it is ( VB or VC++), I am using IDispatch in all the cases, Then, How come i am able to pass disconnected recordset in VB in normalway and i am unable to do that in VC++.

If you are able to get that answer, pl mail me. Here i am trying various combinatins to find out, if i got the answer, i will post that.

Thanks once again
Kishore
nkishore@rediffmail.com

August 30th, 1999, 12:47 AM
Hello All(&Bob),

I am relatively new to both COM and ADO and have a question relating to Bob Place's method of implementing a disconnected recordset in VC.

Does anyone know what code is required for the Client to access this disconnected recordset.

Thanks in Advance.

Grant Taylor.

taylorg@ali.com.au