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

ActiveX server object, first attempt - server.mappath problem

Status
Not open for further replies.

HotMadras

Programmer
Apr 20, 2001
74
GB
I've written a very small DLL to handle calls to a database. It's going to be much bigger and more useful than it is now in future, this is something of a pilot, just to check that I can get it working. Well, at the moment it seems I can't. The only code in the DLL is below:

Public Function getRS(ByVal strSQL As String, ByVal dbName As String)
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset

Set conn = CreateObject("adodb.connection")
conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & dbName
conn.Open

Set rs = CreateObject("ADODB.Recordset")
rs.ActiveConnection = conn
rs.CursorLocation = adUseClient
rs.Source = strSQL
rs.Open strSQL, , adOpenForwardOnly, adLockReadOnly
Set getRS = rs
rs.ActiveConnection = Nothing
conn.Close
Set conn = Nothing

Exit Function
ErrorHandler:
Err.Raise conn.Errors.Item(0).Number, _
conn.Errors.Item(0).Source, _
conn.Errors.Item(0).Description
Set rs = Nothing
Set conn = Nothing
End Function

I use ASP to access this class and attempt to use it to open a recordset:

<%
Dim obj
Dim RS
dim path
path=server.mappath(&quot;database/***.mdb&quot;)
set obj = Server.CreateObject(&quot;DataAccess.clsAccess&quot;)
set RS=obj.getRS(&quot;select * from parts where &quot;, cstr(path))

set obj=nothing

while not rs.eof
%>
<%=RS(&quot;PARTNO&quot;)%><br>
<%
wend
%>

Can anyone spot the problem? Is it with the server.mappath? The error I get is a type mismatch on the line that calls getRS, which makes me think that maybe I've done something stupid.

Thanks for any help.
 
Is your function dimmed correctly?
You use
Public Function getRS(ByVal strSQL As String, ByVal dbName As String)

Should this be:
Public Function getRS(ByVal strSQL As String, ByVal dbName As String) as ADODB.Recordset

Let me know if this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top