I just wrote a simple function in DLL to return a recordset to ASP page. But when the asp page call the function, the dll throw an error on the line that I set the return recordset. Here is the sample code. (The error number that return is 0.!!)
*** VB ***
Public Function fn_getUser(rsUser As Variant) As String
Dim ConnObj As ADODB.Connection
Dim cm As ADODB.Command
Dim rs As ADODB.Recordset
On Error GoTo Errfn_getUser
Set ConnObj = New ADODB.Connection
Set cm = New ADODB.Command
Set rs = New ADODB.Recordset
ConnObj.ConnectionString = sConnStr 'Constanct value
ConnObj.Open
With cm
.ActiveConnection = ConnObj
.CommandText = "sp_getUser"
.CommandType = 4
End With
rs.CursorLocation = adUseClient
rs.Open cm, , adOpenForwardOnly, adLockReadOnly
'This is where the problem is. The stored procedure always returns records, but the return record never get set. Moreover it return an error 0 here.
Set rsUser = rs
ConnObj.Close
Set cm = Nothing
Set rsGroup = Nothing
Set ConnObj = Nothing
Errfn_getUser:
fn_getUser = Err.Number & ": " & Err.Description
End Function
'******************
'***ASP Page********
dim obj, rsUser, msg
set obj=server.CreateObject ("VBCOM_General.IAdmin"
set rsUser= server.CreateObject("ADODB.recordset"
msg = obj.jobscanCache(rsUser)
response.write msg
'******************
'****browser display**
0:
'*****************
If i try to display data from the recordset
response.write rsUser("name"
The page will return an error say the recordset is close.
I wonder that I did any wrong on the dll code for not. Anyone have any idea.. Thank you..
*** VB ***
Public Function fn_getUser(rsUser As Variant) As String
Dim ConnObj As ADODB.Connection
Dim cm As ADODB.Command
Dim rs As ADODB.Recordset
On Error GoTo Errfn_getUser
Set ConnObj = New ADODB.Connection
Set cm = New ADODB.Command
Set rs = New ADODB.Recordset
ConnObj.ConnectionString = sConnStr 'Constanct value
ConnObj.Open
With cm
.ActiveConnection = ConnObj
.CommandText = "sp_getUser"
.CommandType = 4
End With
rs.CursorLocation = adUseClient
rs.Open cm, , adOpenForwardOnly, adLockReadOnly
'This is where the problem is. The stored procedure always returns records, but the return record never get set. Moreover it return an error 0 here.
Set rsUser = rs
ConnObj.Close
Set cm = Nothing
Set rsGroup = Nothing
Set ConnObj = Nothing
Errfn_getUser:
fn_getUser = Err.Number & ": " & Err.Description
End Function
'******************
'***ASP Page********
dim obj, rsUser, msg
set obj=server.CreateObject ("VBCOM_General.IAdmin"
set rsUser= server.CreateObject("ADODB.recordset"
msg = obj.jobscanCache(rsUser)
response.write msg
'******************
'****browser display**
0:
'*****************
If i try to display data from the recordset
response.write rsUser("name"
The page will return an error say the recordset is close.
I wonder that I did any wrong on the dll code for not. Anyone have any idea.. Thank you..