Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error using ADO Object returned from MTS VB Component 1

Status
Not open for further replies.

johnskrb

Programmer
Nov 22, 2000
1
US
I have a VB component running under MTS that returns
an ADODB.Connection object.

When I create the object and call the method from an ASP page, I can use the connection to open a recordset.
When I create the object and call the method (late-bind) from an .EXE on the same machine, I get an ADO type mismatch error when opening a recordset.
If I remove the object from MTS, the recordset works with the returned connection.
Does anyone know what this could be? Some sort of cross-process problem?

I am not using the SafeRef function. I don't think it would
apply here. Am I reading it wrong?
Thanks.
 
Hi

Could you provide your prototypes of your class? (i.e the source code of your class.) You can leave out the program logice and just include the main parts.

eg If you use Properties then

Public Property ReturnedRecordSet AS ???
End Property

or (if you're using a function)

Public Function GetSome As ???

Set GetSome = ????
End Function

And also the code you're using to call your object

It will help in diagnosing the problem.

Hope this helps
caf
 
I get this exact same problem but with the recordset inside the component. I would like to pass the recordset back to the client application. If you could help me out that would be great! Here's my source...

Dim connNorthwind As ADODB.Connection
Dim rsCustomer As ADODB.Recordset
Dim iCustomerID As String
Dim sCompanyName As String

On Error GoTo err_routine

'Instantiate the variables
Set connNorthwind = New ADODB.Connection

'Establish a connection
With connNorthwind
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;Password=;" & _
"Data Source=REGSVRREF3;" & _
"Initial Catalog=Northwind"
.Open
MsgBox "Now connected to database"
End With

'***********Problem occurs in next statement*************
Set rsCustomer = connNorthwind.Execute(sQuery)

iCustomerID = IIf(IsNull(rsCustomer("CustomerID")), 0, rsCustomer!CustomerID)
sCompanyName = IIf(IsNull(rsCustomer("CompanyName")), 0, rsCustomer!CompanyName)

connNorthwind.Close
Set connNorthwind = Nothing

Exit Function

err_routine:

If Err.Number <> 0 Then
Err.Raise Err.Number, , MODULE & &quot;: &quot; & Err.Description
End If

End Function

 
Hi

I pasted the exact same code into an empty propject & did not get an error. You have to check which version of ado you have installed & compare it to mine.

I have ADO version 2.5 SP1 & VB 6 SP4

As to the question of passing data back to the client you have a number of ways to do this

You can set up a function for example

In your class Module (This is just a simple example)
Code:
Option Explicit
Private m_RecordSet As ADODB.RecordSet

Public Property Get ReturnedRecordSet() As ADODB.RecordSet

   Set ReturnedRecordSet = m_RecordSet

End Property

Public Function GetData(iFormat As Integer, sQuery)
Dim TempRecordSet As ADODB.RecordSet
'Data access code here
.....
Set TempRecordSet = connNorthwind.Execute(sQuery.......

.....
If iFormat = 1 'RecordSet
   Set m_RecordSet = TempRecordSet
Elseif iFormat = 2 '2D Array
   GetData = TempRecordSet.GetRows() 'yu can specify some args here
End if

End Function

Now you can call that function/class like this. Let's assume this function resides in Class1 & that Class1 is part of Project1. You calling it from project2.


In Project2
Code:
Dim obj   As ADODB.RecordSet
Dim myArr As Variant

Dim x     As Project1.Class1
Set x = CreateObject(&quot;Project1.Class1&quot;)
'-----------------------------------------------
'             To Get RecordSet back
'-----------------------------------------------
x.GetData(1,&quot;Select * From.....&quot;)

Set obj = x.ReturnedRecordSet
'-----------------------------------------------
'         To Get 2 Dimensional Array back
'-----------------------------------------------

myArr = GetData(2,&quot;Select * From.....&quot;)

'myArr is now a two dimensional array
'myArr(RecordSet_Fields,RecordSet_Rows)

Hope this helps
caf
 
Great.... thanks for the advice. I actually saw a reply you(caf) had made in the Visual Basic(Microsoft) General Discussion forum. Someone mentioned that he had to reinstall the Mdac type libraries. I tried the reinstall and it fixed my problem. It looks like the Mdac type libraries can be a bit touchy. Thanks again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top