Solved

passing recordset from asp to a dll

Posted on 2001-08-01
19
274 Views
Last Modified: 2008-03-06
I'm trying to pass a recordset from an asp page to a dll -- I'm getting a "Type Mismatch"  on the line
If rptServer.RunReport(rs)  then
-- any ideas?

-------------------
ASP page:
<HTML>
<HEAD>
<TITLE>VICC</TITLE>
</HEAD>
<!--#include file='inc/ADOVBS.INC'-->
<%    
     
     Dim rptServer
     Dim fname
     Dim iWhichRpt
     dim strSQL
     dim strTemp
     Dim sSchoolCode
     Dim sDistrictCode      
     dim rs, Con, SQL, cmdtemp
     
     
     Set rptServer = CreateObject("VICCReports.VICCReportServer")
     Set rs        = Server.CreateObject("ADODB.Recordset")
     Set Con       = Server.CreateObject("ADODB.Connection")
     Set cmdTemp   = Server.CreateObject("ADODB.Command")
     
     Con.ConnectionTimeout = Application("Con_ConnectionTimeout")
     Con.CommandTimeout = Application("Con_CommandTimeout")
     Con.Open Application("Con_ConnectionString"), Application("Con_RuntimeUserName"), Application("Con_RuntimePassword")

     
    cmdTemp.CommandText = "StudentReport"
    cmdTemp.CommandType = adCmdStoredProc '4    
    Set cmdTemp.ActiveConnection = Con  
    iWhichRpt = 1
    rptServer.Report = iWhichRpt
    sSchoolCode = "4040"
    sDistrictCode = "bay"
    cmdTemp.Parameters.Append cmdTemp.CreateParameter("sSchoolCode",  adVarChar, adParamInput,4,sSchoolCode)
    cmdTemp.Parameters.Append cmdTemp.CreateParameter("sDistrictCode",  adVarChar, adParamInput,3,sDistrictCode)
    Set rs = cmdTemp.Execute              
         

    rptServer.OutputFormat = 2 ' PDF
    rptServer.EnhancedLogging = True

     If rptServer.RunReport(rs)  then
          fname = rptServer.FileName%>
          <a href="<%=fname%>">Report</a>
     <%
     ELSE
     %>
     <!-- rptServer.RunReport() failed -->
     <BODY>

     <P>
     Error: Unable to create report.<BR>
Try pressing back arrow and trying again. If the problem persists, contact...     </P>

     <%
     END IF
     %>

</BODY>
</HTML>
--------------------------
my VB dll:
Public Function RunReport(rs As ADODB.Recordset) As Boolean
etc.

0
Comment
Question by:pmacmann
  • 5
  • 5
  • 2
  • +6
19 Comments
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Declare the VB function as variant and try like

Public Function RunReport(rs As ADODB.Recordset) As Variant
etc.

0
 
LVL 2

Expert Comment

by:preinsko
Comment Utility
Try setting the cursor to client side.

strConnection.CursorLocation=adUseClient and see if that helps.  Just a thought since I usually only pass one record to my business logic.  
Is there some reason the dll couldn't retreive the recordset based on some query parameters sent to the method?  Seems like overkill to obtain a recordset in asp then pass the whole thing to a dll for actual processing.

0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
In fact you should do it like

Public Function RunReport(rs As Recordset) As Variant

I just helped another person here with a similar problem
http://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20161735
0
 

Author Comment

by:pmacmann
Comment Utility
preinsko -- the dll actually creates a report (using Active Reports) and it was more flexible to have unbound controls in the report -- so I need to pass the recordset to produce the report.

jitganguly -- I need the function as boolean -- it is set to true/false depending on if a report is created.

0
 

Author Comment

by:pmacmann
Comment Utility
jitganguly -- Would
Public Function runReports(rs as variant) as boolean

work?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
NO, use variant
It would be
Public Function runReports(rs as variant) as Variant
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
NO, use variant
It would be
Public Function runReports(rs as variant) as Variant
0
 
LVL 1

Expert Comment

by:pjtt
Comment Utility
Your code looks right to me, especially if you've tried the options given. A quick fix would be to create a property and use that property in the function, ie:

Public Property Set ReportRS(ReportRS As Recordset)
  Set moReportRS = ReportRS
End Property

or something like that...

Peter Tracey
Developer
http://www.25online.com/peter
0
 
LVL 7

Expert Comment

by:John844
Comment Utility
you can return any data type from the function and it will assign it.  

I would not ever use properties for a component as this reduces scalability.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:Maestro
Comment Utility
i use this solution in my dll activex for my asp pages:

Public Function RunReport(rs As object) As Boolean

0
 
LVL 1

Expert Comment

by:Maestro
Comment Utility
the exit function is variant sorry, it was a mistake: use this:

Public Function RunReport(rs As object) As variant
0
 
LVL 3

Expert Comment

by:nigelrowe
Comment Utility
The error might be generated in the DLL. It would be wise to debug it as well.
0
 

Author Comment

by:pmacmann
Comment Utility
I've tried:
Public Function RunReport(rs As ADODB.Recordset) As Boolean
Public Function runReport(rs As Variant) As Variant
Public Function RunReport(rs As Object) As Variant

and continue to get the type mismatch. When I run the dll from VB - it works great. It is obtaining the recordset from a SQL stored procedure (and that hasn't changed from running it in VB or trying to run it from asp).

I'm rather new to VB -- do you have a suggestion of how to trap the error in the dll (if that's the case) and write it in the app.logevent or pass it back?

thanks.
0
 
LVL 1

Expert Comment

by:BenBen
Comment Utility
Try
public proporty set RS(RS as adodb.recordset)
OR a much better soultion (IMHO) would be to pass the CONNECTION STRING AND THE QUERY to VB and use VB to connect. To debug this application, try doing this. Make a new project that is the same as your ASP code. (the vbs part) and set the dll to run that when ever it is debugged. put a break on every line
0
 

Author Comment

by:pmacmann
Comment Utility
Actually, this application runs fine in VB - it's just when I try to reference the dll from asp that I get the type mismatch.
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
What is preventing you to do it like
Public Function RunReport(rs As ADODB.Recordset) As Variant

and use cstr function of vbscript to access it. It shoudl be simple

0
 
LVL 1

Expert Comment

by:BenBen
Comment Utility
Try doing

Public proporty set rs (rs as object)

Because vbs has no dim as ____ statements i think the mechiene just cant handle that.
0
 

Author Comment

by:pmacmann
Comment Utility
I've tried all of these suggestions -- I think it may be a problem with Active Reports. I'll keep you posted. thanks for all of your help.
0
 
LVL 1

Accepted Solution

by:
jswalia earned 100 total points
Comment Utility
Try something like this:

' define your local recordset on ASP Page
set rs = server.CreateObject("ADODB.RecordSet")

' define your Dll Class
set clsD = server.CreateObject("WEBDataDll.clsData")
   
' make SQl string
strSQL = "Select cUserid,cPassword from Users where "
strsql = strsql & "upper"(cUserID) = '"
strsql = strsql & ucase(Request.Form("UID")) & "'"

' Call your function from Dll & assign it to the local recordset variable
' See carefully that we are passing the parameter in 2 braces, which is the MAIN thing to do

set rs = clsD.GetRecordset((strSQL))

if NOT rs.BOF then

else

endif
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now