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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i Open a recordset returned from DLL

Status
Not open for further replies.

FaisalHenry

Programmer
Dec 19, 2000
32
0
0
US
I am trying to implement a 3 tier architecture here,
a DLL named DataServices, have a class PassengerData, with a method GetPassengersData that have a Recordset Return type.

The code is listed below:
Public Function getpassengersdata() As ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection

cn.ConnectionString= "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"DataSource=c:\1cruiseline\database\dbcruise.mdb"
cn.Open
rs.Open "qryPassenger", cn
rs.MoveFirst
Set getpassengerdata = rs
End Function

I tried to access the DLL with this code:
Private Sub Command1_Click()
Dim objPassenger As Object
Dim rs As New ADODB.Recordset

Set objPassenger = CreateObject("dataservices.passengerdata")
Set rs = objPassenger.getpassengersdata
rs.MoveFirst
End Sub

at the rs.MoveFirst code i got a run time error 3704, it says that the operation is not allowed if the object is closed

But if i use the rs.Open command, i need a valid connection,
this is not the kind of behavior that i want.

Any suggestion on how to open the RecordSet ?
 
Hi,

I bit of a different approach (don't know if it will help you...)

In the calling sub or function:

Dim rst as recordset
set rst=new recordset
Call YourFunction(byref rst as recordset)

In 'YourFunction' ->open the recordset passed to the function. The recordset is accessible to the calling sub straight away since it's only passed byref.

Mats
 
I first set the CursorLocation property:

rs.CursorLocation = adUseClient

and then when opening the recordset in DLL I use:

rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText

i.e. with 3 extra options set to you.

Remember that when you copy the DLLs recordset to a local one, it inherits the properties, but loses the connection. Thus, as the default recordset behaviour is Dynamic, it is obviously struggling when it suddenly finds itself without a connection. By setting the recordset to Static you should solve the problem, and no longer need to open the connection at the client side.

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top