p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

asp_components thread: ASP DLL component, ADO problem


Message #1 by "Ayman Awadi" <aymawadi@y...> on Sun, 26 May 2002 07:07:32
Hello,
I am facing a little problem with ActiveX DLL?s, I hope someone could give 
a hand. The DLL is using ADO to connect to an MDB file, it contains a 
simple method to fetch a row from a given table.
Here is the code

'----------------------------------------------
Private m_cnnRe As ADODB.Connection
Private m_rsCustomers As ADODB.Recordset

Private Sub Class_Initialize()
Dim sErr As String
    On Error GoTo Err_Routine
    sErr = ""
    
    Set m_cnnRe = New ADODB.Connection
    m_cnnRe.CursorLocation = adUseServer
    
    Set m_rsCustomers = New ADODB.Recordset
    m_rsCustomers.CursorLocation = adUseServer
Exit_Point:
    If sErr <> "" Then
        Class_Terminate
        Err.Raise 40000, "Initialize", sErr & _
                         " Unable to initialize the class"
    End If
    Exit Sub
Err_Routine:
    sErr = "[" & Err.Number & "] " & Err.Description
    GoTo Exit_Point
End Sub

Private Sub Class_Terminate()
    If Not m_rsCustomers Is Nothing Then
        If m_rsCustomers.State <> adStateClosed Then
            m_rsCustomers.Close
        End If
    End If
    If Not m_cnnRe Is Nothing Then
        If m_cnnRe.State <> adStateClosed Then
            m_cnnRe.Close
        End If
    End If
    Set m_rsCustomers = Nothing
    Set m_cnnRe = Nothing
End Sub

Public Sub OpenDataSource(ByVal sConnect As String)
Dim sErr As String
    On Error GoTo Err_Routine
    sErr = ""
    
    m_cnnRe.Open sConnect
Exit_Point:
    If sErr <> "" Then
        Err.Raise 40001, "OpenDataSource", sErr & _
                         " Unable to open connection"
    End If
    Exit Sub
Err_Routine:
    sErr = "[" & Err.Number & "] " & Err.Description
    GoTo Exit_Point
End Sub

Public Function GetRow(ByVal lKey As Long) As String
Dim sErr As String, sSql As String
    On Error GoTo Err_Routine
    sErr = ""
    sSql = "Select Customers.* From Customers " & _
           "Where(CustomerSerial = " & lKey & ");"
    m_rsCustomers.Open sSql, m_cnnRe, adOpenForwardOnly, adLockReadOnly
    GetRow = m_rsCustomers!CustomerName & ""
Exit_Point:
    If sErr <> "" Then
        Err.Raise 40002, "GetRow", sErr & " Unable to get the row"
    End If
    Exit Function
Err_Routine:
    sErr = "[" & Err.Number & "] " & Err.Description
    GoTo Exit_Point
End Function
'----------------------------------------------

The DLL runs perfect when used from within a standalone EXE, I simply 
added another EXE project, then used the follwoing code to test it

'----------------------------------------------
Private Sub Form_Load()
Dim cls As DllTester.SimpleAdo, sName As String
    On Error GoTo Err_Routine
    Set cls = New DllTester.SimpleAdo
    cls.OpenDataSource "Provider=Microsoft.Jet.OLEDB.3.51;" & _
                       "Persist Security Info=False;Data Source=" & _
                       "G:\Acc-Main\Re99\C70\R70Main.mdb"
    sName = cls.GetRow(1)
    MsgBox sName
Exit_Point:
    Set cls = Nothing
    Exit Sub
Err_Routine:
    MsgBox Err.Number & Err.Description
    GoTo Exit_Point
End Sub
'----------------------------------------------

After this, I thought the DLL is ready, so I compiled it, copied the 
DllTester.lib, DLLTester.dll, DLLTester.exp to my IIS server running at 
WinNT 4.0 SP6, I put the three files somewhere under WinNT\system32, then 
I used the REGSVR32 to register the DLL.

Next, I tried to use the DLL from an ASP, as follows

'----------------------------------------------
<% Response.Buffer = false %>
<%
	Response.Write "<HTML>"
	Response.Write "<HEAD>"
	Response.Write "<META NAME='GENERATOR' " & _
                       "Content='Microsoft Visual Studio 6.0'>"
	Response.Write "<TITLE>Testing COM</TITLE>"
	Response.Write "</HEAD>"
	Response.Write "<BODY>"
	Response.Write "<P>DLL Tester<P>"
	
	'on error resume next
	dim m_clsTester
	set m_clsTester = Server.CreateObject("DllTester.SimpleAdo")
	
	if err.number <> 0 then
		Response.Write "<P>Error: " & Err.Description & "</P>"
	else
		sCnn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
                 "Persist Security Info=False;Data Source=" & _
			  "E:\Acc-Main\Re99\C70\R70Main.mdb"
		m_clsTester.OpenDataSource sCnn
		if err.number <> 0 then
			Response.Write "<P>Error: " & _
                                Err.Description & "</P>"
		end if
		
		sName = m_clsTester.GetRow(1)
		if err.number <> 0 then
			Response.Write "<P>Error: " & _
                                Err.Description & "</P>"
		end if
		Response.Write "<P>Name: " & sName & "</P>"
	end if
	set m_clsTester = nothing

	Response.Write "</BODY>"
	Response.Write "</HTML>"
%>
'----------------------------------------------

Now,, for my surprise, when I navigated to this ASP page, I got this 

DLL Tester 
Initialize error '800a9c40' 
[430] Class does not support Automation or does not support expected 
interface Unable to initialize the class 
/test3.asp, line 14 

Notice that the message ?Unable to initialize the class? comes from 
Class_Initialize in my code above, Line 14 is the line where I used 
CreateObject in the ASP page??

What could be wrong here??
I have created a reference to the ADO 2.5 in the DLLTester.DLL project!! 
Is that enough? Do I have to package the DLLTester.DLL and install it on 
my NT server? Isn?t REGSVR32 enough? I have tried to make a very simpl 
ActiveXDLL (not using ADO), just a very simple one, and it worked perfect 
by simply regestering it with REGSVR32!!!

Where did I go wrong, Please help ?

Thank you all

A. Awadi
Message #2 by "Joe Hughes" <JoeHughes@M...> on Sun, 26 May 2002 11:47:21 +0100
HI Ayman,

Do you have MDAC (2.5?) installed on the WinNT Server running IIS?

Joe 

-----Original Message-----
From: Ayman Awadi [mailto:aymawadi@y...] 
Sent: 26 May 2002 07:08
To: ASP components
Subject: [asp_components] ASP DLL component, ADO problem


Hello,
I am facing a little problem with ActiveX DLL's, I hope someone could
give 
a hand. The DLL is using ADO to connect to an MDB file, it contains a 
simple method to fetch a row from a given table.
Here is the code

'----------------------------------------------
Private m_cnnRe As ADODB.Connection
Private m_rsCustomers As ADODB.Recordset

Private Sub Class_Initialize()
Dim sErr As String
    On Error GoTo Err_Routine
    sErr = ""
    
    Set m_cnnRe = New ADODB.Connection
    m_cnnRe.CursorLocation = adUseServer
    
    Set m_rsCustomers = New ADODB.Recordset
    m_rsCustomers.CursorLocation = adUseServer
Exit_Point:
    If sErr <> "" Then
        Class_Terminate
        Err.Raise 40000, "Initialize", sErr & _
                         " Unable to initialize the class"
    End If
    Exit Sub
Err_Routine:
    sErr = "[" & Err.Number & "] " & Err.Description
    GoTo Exit_Point
End Sub

Private Sub Class_Terminate()
    If Not m_rsCustomers Is Nothing Then
        If m_rsCustomers.State <> adStateClosed Then
            m_rsCustomers.Close
        End If
    End If
    If Not m_cnnRe Is Nothing Then
        If m_cnnRe.State <> adStateClosed Then
            m_cnnRe.Close
        End If
    End If
    Set m_rsCustomers = Nothing
    Set m_cnnRe = Nothing
End Sub

Public Sub OpenDataSource(ByVal sConnect As String)
Dim sErr As String
    On Error GoTo Err_Routine
    sErr = ""
    
    m_cnnRe.Open sConnect
Exit_Point:
    If sErr <> "" Then
        Err.Raise 40001, "OpenDataSource", sErr & _
                         " Unable to open connection"
    End If
    Exit Sub
Err_Routine:
    sErr = "[" & Err.Number & "] " & Err.Description
    GoTo Exit_Point
End Sub

Public Function GetRow(ByVal lKey As Long) As String
Dim sErr As String, sSql As String
    On Error GoTo Err_Routine
    sErr = ""
    sSql = "Select Customers.* From Customers " & _
           "Where(CustomerSerial = " & lKey & ");"
    m_rsCustomers.Open sSql, m_cnnRe, adOpenForwardOnly, adLockReadOnly
    GetRow = m_rsCustomers!CustomerName & ""
Exit_Point:
    If sErr <> "" Then
        Err.Raise 40002, "GetRow", sErr & " Unable to get the row"
    End If
    Exit Function
Err_Routine:
    sErr = "[" & Err.Number & "] " & Err.Description
    GoTo Exit_Point
End Function
'----------------------------------------------

The DLL runs perfect when used from within a standalone EXE, I simply 
added another EXE project, then used the follwoing code to test it

'----------------------------------------------
Private Sub Form_Load()
Dim cls As DllTester.SimpleAdo, sName As String
    On Error GoTo Err_Routine
    Set cls = New DllTester.SimpleAdo
    cls.OpenDataSource "Provider=Microsoft.Jet.OLEDB.3.51;" & _
                       "Persist Security Info=False;Data Source=" & _
                       "G:\Acc-Main\Re99\C70\R70Main.mdb"
    sName = cls.GetRow(1)
    MsgBox sName
Exit_Point:
    Set cls = Nothing
    Exit Sub
Err_Routine:
    MsgBox Err.Number & Err.Description
    GoTo Exit_Point
End Sub
'----------------------------------------------

After this, I thought the DLL is ready, so I compiled it, copied the 
DllTester.lib, DLLTester.dll, DLLTester.exp to my IIS server running at 
WinNT 4.0 SP6, I put the three files somewhere under WinNT\system32,
then 
I used the REGSVR32 to register the DLL.

Next, I tried to use the DLL from an ASP, as follows

'----------------------------------------------
<% Response.Buffer = false %>
<%
	Response.Write "<HTML>"
	Response.Write "<HEAD>"
	Response.Write "<META NAME='GENERATOR' " & _
                       "Content='Microsoft Visual Studio 6.0'>"
	Response.Write "<TITLE>Testing COM</TITLE>"
	Response.Write "</HEAD>"
	Response.Write "<BODY>"
	Response.Write "<P>DLL Tester<P>"
	
	'on error resume next
	dim m_clsTester
	set m_clsTester = Server.CreateObject("DllTester.SimpleAdo")
	
	if err.number <> 0 then
		Response.Write "<P>Error: " & Err.Description & "</P>"
	else
		sCnn = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
                 "Persist Security Info=False;Data Source=" & _
			  "E:\Acc-Main\Re99\C70\R70Main.mdb"
		m_clsTester.OpenDataSource sCnn
		if err.number <> 0 then
			Response.Write "<P>Error: " & _
                                Err.Description & "</P>"
		end if
		
		sName = m_clsTester.GetRow(1)
		if err.number <> 0 then
			Response.Write "<P>Error: " & _
                                Err.Description & "</P>"
		end if
		Response.Write "<P>Name: " & sName & "</P>"
	end if
	set m_clsTester = nothing

	Response.Write "</BODY>"
	Response.Write "</HTML>"
%>
'----------------------------------------------

Now,, for my surprise, when I navigated to this ASP page, I got this 

DLL Tester 
Initialize error '800a9c40' 
[430] Class does not support Automation or does not support expected 
interface Unable to initialize the class 
/test3.asp, line 14 

Notice that the message "Unable to initialize the class" comes from 
Class_Initialize in my code above, Line 14 is the line where I used 
CreateObject in the ASP page??

What could be wrong here??
I have created a reference to the ADO 2.5 in the DLLTester.DLL project!!

Is that enough? Do I have to package the DLLTester.DLL and install it on

my NT server? Isn't REGSVR32 enough? I have tried to make a very simpl 
ActiveXDLL (not using ADO), just a very simple one, and it worked
perfect 
by simply regestering it with REGSVR32!!!

Where did I go wrong, Please help ?

Thank you all

A. Awadi
 
---
You are currently subscribed to asp_components as: joehughes@m... To
unsubscribe send a blank email to
%%email.unsub%%



Message #3 by "Ayman Awadi" <aymawadi@y...> on Mon, 27 May 2002 07:33:57
Hi Joe,

Yes, It's installed. Luckily after reading your email, I decided to check 
the ADO version number (too late I guess), and found that my NT has ADO 
2.0 instead.

I think this is the problem, isn't it? many thanks to you.

A. Awadi

  Return to Index