G
Guest
Dear Friends,
I'm trying to create a .NET class named TESTE using VB.NET that can be
called by an ASP page but I got an error that I could not fix.
TEST CLASS code:
==========
Imports System.Web.Mail
Public Class update
Public update As String
Public server As String
Public database As String
Dim strConnect As String
Dim SQLStmt As String
Dim dbConn, dbComm, dbRead
Dim name
Public Function envia()
strConnect = "Provider=SQLOLEDB;Server=" + server + ";Database=" +
database + ";Trusted_Connection=yes"
dbConn = New System.Data.OleDb.OleDbConnection(strConnect)
dbConn.Open()
SQLStmt = " select "
SQLStmt = SQLStmt & " name "
SQLStmt = SQLStmt & "from "
SQLStmt = SQLStmt & " table "
SQLStmt = SQLStmt & "where "
SQLStmt = SQLStmt & " status = 's' "
dbComm = New System.Data.OleDb.OleDbCommand(SQLStmt, dbConn)
dbRead = dbComm.ExecuteReader()
If dbRead.read() Then
name = dbRead("name")
End If
Return name
'----------------------------------------------
End Function
End Class
To compyle this DLL I'm setting PROPERTIES/CONFIGURATION PROPERTIES/BUILD as
Register for COM Interop so VS compilation creates a .DLL and a .TLB file.
After that I put this 2 files (dll and tlb) into my server and register it
using the following command:
REGASM teste.dll /tlb teste.tlb /codebase
TESTE.ASP Code that calls my .NET Class:
========================
<%
Dim obj
set obj = Server.CreateObject("teste.update")
obj.update = "resultado"
obj.server = "servername"
obj.database = "databasename"
response.write obj.envia()
%>
When executed, this page returns the following error message:
mscorlib error '80131604'
Exception has been thrown by the target of an invocation.
/teste.asp, line 7
I could see that it only occurs when I call
When I clear all code leaving just the below code it works fine without any
error message, but if I include dbConn.Open() the error returns to apear.
Public Function envia()
strConnect = "Provider=SQLOLEDB;Server=" + server + ";Database=" +
database + ";Trusted_Connection=yes"
dbConn = New System.Data.OleDb.OleDbConnection(strConnect)
Return strConnect
'----------------------------------------------
End Function
End Class
Can anyone help me?
I'm trying to create a .NET class named TESTE using VB.NET that can be
called by an ASP page but I got an error that I could not fix.
TEST CLASS code:
==========
Imports System.Web.Mail
Public Class update
Public update As String
Public server As String
Public database As String
Dim strConnect As String
Dim SQLStmt As String
Dim dbConn, dbComm, dbRead
Dim name
Public Function envia()
strConnect = "Provider=SQLOLEDB;Server=" + server + ";Database=" +
database + ";Trusted_Connection=yes"
dbConn = New System.Data.OleDb.OleDbConnection(strConnect)
dbConn.Open()
SQLStmt = " select "
SQLStmt = SQLStmt & " name "
SQLStmt = SQLStmt & "from "
SQLStmt = SQLStmt & " table "
SQLStmt = SQLStmt & "where "
SQLStmt = SQLStmt & " status = 's' "
dbComm = New System.Data.OleDb.OleDbCommand(SQLStmt, dbConn)
dbRead = dbComm.ExecuteReader()
If dbRead.read() Then
name = dbRead("name")
End If
Return name
'----------------------------------------------
End Function
End Class
To compyle this DLL I'm setting PROPERTIES/CONFIGURATION PROPERTIES/BUILD as
Register for COM Interop so VS compilation creates a .DLL and a .TLB file.
After that I put this 2 files (dll and tlb) into my server and register it
using the following command:
REGASM teste.dll /tlb teste.tlb /codebase
TESTE.ASP Code that calls my .NET Class:
========================
<%
Dim obj
set obj = Server.CreateObject("teste.update")
obj.update = "resultado"
obj.server = "servername"
obj.database = "databasename"
response.write obj.envia()
%>
When executed, this page returns the following error message:
mscorlib error '80131604'
Exception has been thrown by the target of an invocation.
/teste.asp, line 7
I could see that it only occurs when I call
When I clear all code leaving just the below code it works fine without any
error message, but if I include dbConn.Open() the error returns to apear.
Public Function envia()
strConnect = "Provider=SQLOLEDB;Server=" + server + ";Database=" +
database + ";Trusted_Connection=yes"
dbConn = New System.Data.OleDb.OleDbConnection(strConnect)
Return strConnect
'----------------------------------------------
End Function
End Class
Can anyone help me?