Link to home
Start Free TrialLog in
Avatar of mfarid1
mfarid1

asked on

ADO Recordset Clone and ADO Provider

I am using Microsoft OLEDB Provider for ODBC. I have used the default provider and also SQLOLEDB.1
I simply cannot do
Set rsA = rsB.Clone

I absolutely need to do this to get a recordcount.

I am using VB6, ADO and SQL Server 7
Avatar of mfarid1
mfarid1

ASKER

The message I get is something like, This feature is not supported by my provider
Use the MSDASQL provider. It works fine for me my connect string is
"Provider=MSDASQL.1;Connect Timeout=15;Extended Properties="DRIVER=sql server;SERVER=uk-ins-fs18;UID=sa;PWD=;APP=Visual Basic;WSID=INS573;DATABASE=GarwynApp";Locale Identifier=2057"
I have got latest Data access Components sql server odbc driver 3.7
Avatar of mfarid1

ASKER

Same Error. This is what I get:

Run-time Error 3251
The operation requested by the application is not supported by the provider.
What version of ODBC drivers do you have?
Avatar of mfarid1

ASKER

3.70.06.90 SQLSRVR32.DLL 4/1/99
ASKER CERTIFIED SOLUTION
Avatar of enkay022798
enkay022798

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mfarid1

ASKER

What do you mean by disconnecting? do you mean setting the connection to nothing?

I tried it and it did not work:

I got the recordset with the data.

Dim rsA As ADODB.Recordset
Dim rsB As ADODB.Recordset

Set rsA = ('Get recordset from SQL')
cn.Close

Set rsTemp = rsA.Clone

I get the following error:
Run-time error 3704

The operation requested by the application is not allowed if the object is closed.

Disconnecting is not setting the connection object to nothing. I am pasting the corrected code from your example

       Dim rsA As ADODB.Recordset
       Dim rsB As ADODB.Recordset

       Set rsA = ('Get recordset from SQL')
       ' cn.Close --> this is wrong
       set rsA.ActiveConnection = nothing  ' this will disconnect the recordset from the connection

       Set rsTemp = rsA.Clone ' now this should work

You also need to do the following stuff to disconnect a recordset

      CursorLocation should be client side
      CursorType should be Static
      LockType should be UpdateBatchOptimistic

You can reconnect the recordset to the connection object mush the same way after you finish processing the data in it

     set rsA.ActiveConnection = cn

And then fire the Update or UpdateBatch method to committ your changes

Hope this works for you. I can assure you that it will. LEt me know if you need any more info or have any more problems with this.

Regards,
enkay.
Avatar of mfarid1

ASKER

Does not work.

I have tried the following:

Dim rsA As ADODB.Recordset
Dim rsB As ADODB.Recordset
Note: pConn is a previous active connection

rsADO.Open "sp_Tables", pConn, adOpenStatic, adLockBatchOptimistic, adCmdStoredProc
'The above statement works fine

'Tried this FIRST
Set rsB = rsA.Clone

'Get this error message:
'Run-time error 3251
'The operation requested by the application is not 'supported by the provider

'Tried this SECOND
Set rsA.ActiveConnection = Nothing
'Get the following error:
'Run-time error 3705
'The operation requested by the application is not allowed 'if the object is open

'Tried this THIRD
rsA.Close
Set rsA.ActiveConnection = Nothing
Set rsB = rsA.Clone
'Get the following error:
'Run-time error 3704
'The operation requested by the application is not allowed 'if the object is closed on the last line

The stored proc I am trying to execute is a stored proc that comes with SQL Server named 'sp_Tables'. If you can send me some code as how that stored procedure can be made to work and get a recordcount then I would greatly appreciate it. If I can provide any other information, please let me know.
Are you haveing a Client side cursor? If the connection is opened using server side cursors it will override whatever similar properties that you will define for any object (command , recordset etc) that uses that connection. Can you give me the connection string and the connection object properties that you are having at the time you execute the above code.

I am using this all through my applications and it works just fine. And I am using SQL server as the backend as wll. There must be some property which is not getting a proper value due to which you are not able to disconnect.
Avatar of mfarid1

ASKER

enkay, you are the man. It worked!!! Actually, the only thing I needed to do was use a CursorLocation of adUseClient on the Connection, not on the recordset or the command object. Its amazing how long this took me and how few people know about this.