Passing a Recordset from VB6 to VB.Net (QueryInterface failed.)



I am getting an error when trying to use an ADODB.Recordset that was passed
from a VB6 application to a VB.Net class library using COM Interop. I am
running this on WinXP SP2 using the .Net Framework 1.1 and MDAC 2.8 SP1.

This is what I've done:
- I compiled the VB.Net DLL and registered it so it can be used in the VB6
app using "regasm /tlb:VBNETClass.tlb VBNETClass.dll".
- From the VB6 app, I added a reference to the VB.Net DLL.
- I added references to the ADO 2.8 Library from both the VB6 app and the
VB.Net library. (I also tried ADO 2.6 and 2.7 later but they had the same
- I built the VB6 EXE and copied it to the directory containing the VB.Net

When I run the VB6 EXE, all of the message boxes appear fine except for the
one on the last line of PrintRecordCount below. Instead, I get the following

- - - -
Run-time error '-2147467262 (80004002)';
QueryInterface for interface ADODB._Recordset failed.
- - - -
(The debugger shows it to be a System.InvalidCastException.)

Any ideas?


Private Sub Command1_Click()

Dim ccw As New VBNETClass.Class1

Dim rs As New ADODB.Recordset
Set rs = CreateObject("ADODB.Recordset")
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.Fields.Append "FieldName1", adVarChar, 10
rs.Fields.Append "FieldName2", adInteger

rs("FieldName1") = "David"
rs("FieldName2") = 17

rs.Sort = "FieldName2"

MsgBox ("In VB6 App, about to call VB.Net class...")
' this line works
MsgBox ("In VB6 Class, rs.RecordCount = " & rs.RecordCount)

ccw.PrintRecordCount (rs)

End Sub


Public Class Class1
Public Function PrintRecordCount(ByVal rs As ADODB.Recordset)

MsgBox("In VB.Net Class, about to display RecordCount... ")
' this line produces the error
MsgBox("In VB.Net Class, rs.RecordCount = " & rs.RecordCount)

End Function
End Class

(I also tried changing the type of the input parameter to
ADODB.RecordsetClass and ADODB._Recordset but the same error resulted.)

Peter Huang [MSFT]


I reviewed the thread and find that there is a similar issue in the
newsgroup below.Now I have replied to you, you may go and take a look.
Newsgroups: microsoft.public.dotnet.framework.interop
Subject: Passing a Recordset from VB6 to VB.Net (QueryInterface failed.)

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! -
This posting is provided "AS IS" with no warranties, and confers no rights.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question