How to disconnect the recordset that has been upgraded to .Net

Hi,

I have a function "FetchRecset" that just populates the recordset when the SQL string or the stored proc name is passed and it looks like this in VB6.0.

Public Function FetchDiscRecSet(CmdSQL As String, _
rsResultSet As ADODB.Recordset, _
Optional Updateable As Boolean = False) As ErrInfo

Dim cnConnection As ADODB.Connection
Dim rsTemp As ADODB.Recordset
Dim strConnectString As String

'Initialize connection object
Set cnConnection = New ADODB.Connection
cnConnection.CommandTimeout = c_Timeout
cnConnection.Open gc_ConnectionString

Set rsTemp = New ADODB.Recordset
With rsTemp
.ActiveConnection = cnConnection
.CursorType = adOpenStatic
.CursorLocation = adUseClient
If Updateable Then
.LockType = adLockBatchOptimistic
End If
.Source = CmdSQL
.Open
.ActiveConnection = Nothing
End With

Set rsResultSet = rsTemp
Set cnConnection = Nothing

Set rsTemp = Nothing
------
After I upgrade the project to .Net it looks like this

--------

Public Function FetchDiscRecSet(ByRef CmdSQL As String, ByRef rsResultSet As ADODB.Recordset, Optional ByRef Updateable As Boolean = False) As ClsError.ErrInfo

Dim cnConnection As ADODB.Connection

Dim rsTemp As ADODB.Recordset

Dim strConnectString As String

'Initialize connection object

cnConnection = New ADODB.Connection

cnConnection.CommandTimeout = c_Timeout

cnConnection.Open(gc_ConnectionString)

rsTemp = New ADODB.Recordset

With rsTemp

.let_ActiveConnection(cnConnection)

.CursorType = ADODB.CursorTypeEnum.adOpenStatic

.CursorLocation = ADODB.CursorLocationEnum.adUseClient

If Updateable Then

.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic

End If

.let_Source(CmdSQL)

.Open()

'UPGRADE_NOTE: Object rsTemp.ActiveConnection may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'

.let_ActiveConnection(Nothing)

End With

rsResultSet = rsTemp

'UPGRADE_NOTE: Object cnConnection may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'

cnConnection = Nothing

rsTemp = Nothing

--

The Problem I have is when this function is called the recordset is passed by reference and when it reaches the ".let_ActiveConnection(Nothing)" statement, it errors out with this message.

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

What should I do to disconnect the recordset in .Net. The connection string value is like this

"Provider=SQLOLEDB;User ID = aaaa;Password = xxxxx;Initial Catalog=c1;Data Source=d22"

Thanks in advance,

SS



Answer this question

How to disconnect the recordset that has been upgraded to .Net

  • Steve Furby


    Try changing the .let_ActiveConnection statements to the following:

    .ActiveConnection = cnConnection

    and

    .ActiveConnection = Nothing

    I believe the let_ method was added to handle connection strings and not connection objects.



  • giarnz

    Thanks. It works now. But another recordset when opened gives me this error
    Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.

    I'm not trying to update the recordset or anything.

    Thanks,

    SS


  • barbbayne

    I resolved this issue by passing the value rather than the object itself to the called procedure. Thanks for all your help.


  • su45937


    Do you have a sample of the code and can you identify where the error occurs

  • How to disconnect the recordset that has been upgraded to .Net