View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
TK TK is offline
external usenet poster
 
Posts: 177
Default VB6.0 ADO question

Hi Christmas May

You can close like this before Exit Sub/Function
and the error handler

'close connection
conn.Close
Set ocnn = Nothing
Set rs = Nothing

Exit Sub/Function

I don't have server but if you would like a sample to test that
connects to Access's Northwind that does work post back and
I'll post you one. It will work on server you will need to change
connection and cat # ect.

Good Luck
TK


"Christmas May" wrote:

Most of the following code was obtained from Microsoft. (Unsure what I've
changed.) However, it does not work correctly. I'm hoping someone can tell
me why. It actually works until the "GetObjectContext.SetComplete" line us
unremarked. It also bothers me that neither the recordset nor the connection
are closed/terminated nicely.

Public Function ListAll() As ADODB.Recordset

Dim strSQL As String
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection

On Error GoTo ErrorHandler

'Form the SQL SELECT statement
strSQL = "SELECT CategoryId, Name, ModifiedDate, CreatedDate " & _
"FROM Categories ORDER BY Name"

set rs = new ADODB.Recordset
rs.CursorLocation = adUseClient

'Execute the SQL command to the database, using the recordset Open method.
rs.Open strSQL, "FILEDSN=" & fileDSN, adOpenKeyset, adlLockReadOnly,
adCmdText

GetObjectContext.SetComplete

Set ListAll=rs

Exit Function

ErrorHandler:
If Not rs Is Nothing Then
Set rs=Nothing
End If

'Roll back MTS transaction set.
Err.Raise Err.Number, SetErrSource(modName, "ListAll"), Err.Description

GetObjectContext.SetAbort
Err.Raise Err.Number, SetErrSource(modName, "ListAll"), Err.Description

End Function

Thanks in advance,

Christmas May