Hope someone can help.
I need to instantiate a .NET class from ASP (Not ASP.NET). I compile the class and add it to the global assembly cache. I then run regasm to great a type for the ASP server.createobject call to work.
Here's the problem. It all runs perfectly on my development pc... (WinXP, Visual Studio.NET) and I get the expected iResult of 0 which means a successful connection to oracle. But when I copy the dll and the asp files to my development server (Win2K, .NET Framework) the iResult value returned from the function call is a -1 which indicates a failure. The dll spins up fine, calls to the dll work (and return data - that's the reason why I've got that fnTest().. Just to check a simple function) but I have no idea why I can't connect to my oracle database.
My pc and the dev server are in the same domain, both have oranames correctly configured for the TSN NAME for be found (TNSPING works from both machines).
I've included the source code for the two files... A VB class and a ASP file. Shout if you need more info. I was wondering is this was a permissions problem maybe, but couldnt spot anything obvious in the permissions.
You'll note that fnGENMessageBox calls are commented out in the class... This is cause I haven't bothered inserting the function into this test class yet.
Thanks.
------------------START VB------------------------
------
Imports System.Reflection
<Assembly: AssemblyKeyFileAttribute("
M:\Microso
ft Visual Basic.NET\TestSDClass\Test
SDClass.sn
k")>
Public Class clsTestSDClass
#Region "Global Declares"
Private oCNN As ADODB.Connection
Private oPRM As ADODB.Parameter
Private oCMD As ADODB.Command
Private oSTR As ADODB.Stream
Private iRows As Integer
Private oRS As ADODB.Recordset
' Return Value Constants
Private Const S_OK As Long = 0
Private Const S_FAILURE As Long = -1
Private bConnected As Boolean ' Are we connected to the database
' Database Environment
Public Enum clsSDEnvironmentEnum As Integer
enumENVNotSet = 0
enumENVDevelopment = 1
enumENVIntegration = 2
enumENVProduction = 3
End Enum
' Property Variables
Private mEnvironment As Integer ' What database environment are we in
Private mTNSName As String ' Oracle TNS Names Identifier
Private mSMTPServerName As String ' SMTP Message Server
Private mSMTPProfileName As String ' SMTP Send Profile
Private mEmailSupportGroup As String ' Email Support Group
#End Region
#Region "Property Assignments"
Public Property EmailSupportGroup() As String
Get
Return mEmailSupportGroup
End Get
Set(ByVal Value As String)
mEmailSupportGroup = Value
End Set
End Property
Public Property Environment() As Integer
Get
Return mEnvironment
End Get
Set(ByVal Value As Integer)
mEnvironment = Value
End Set
End Property
Public Property TNSNames() As String
Get
Return mTNSName
End Get
Set(ByVal Value As String)
mTNSName = Value
End Set
End Property
Public Property SMTPServerName() As String
Get
Return mSMTPServerName
End Get
Set(ByVal Value As String)
mSMTPServerName = Value
End Set
End Property
Public Property SMTPProfileName() As String
Get
Return mSMTPProfileName
End Get
Set(ByVal Value As String)
mSMTPProfileName = Value
End Set
End Property
#End Region
Public Function fnGENConnectDatabase() As Integer
Dim sUserID As String
Dim sPassword As String
On Error GoTo fnGENConnectDatabase_Error
bConnected = False
fnGENConnectDatabase = S_FAILURE
' Preprocessing validation
If mEnvironment = clsSDEnvironmentEnum.enumE
NVNotSet Then
'fnGENMessageBox("fnGENCon
nectDataba
se: An error has occurred during startup. Please provide a Data Environment.", vbCritical + vbOKOnly)
Exit Function
End If
Select Case mEnvironment
Case clsSDEnvironmentEnum.enumE
NVDevelopm
ent
sUserID = "NOTTELLING"
sPassword = "NOTTELLING"
Case clsSDEnvironmentEnum.enumE
NVIntegrat
ion
sUserID = "NOTTELLING"
sPassword = "NOTTELLING"
Case clsSDEnvironmentEnum.enumE
NVProducti
on
sUserID = "NOTTELLING"
sPassword = "NOTTELLING"
End Select
'If mTNSName = vbNullString Then
' 'fnGENMessageBox("fnGENCon
nectDataba
se: An error has occurred during startup. Please provide an Oracle TNS Names entry.", vbCritical + vbOKOnly)
' Exit Function
'End If
'If mSMTPServerName = vbNullString Then
' 'fnGENMessageBox("fnGENCon
nectDataba
se: An error has occurred during startup. Please provide an SMTP Server Name for error processing.", vbCritical + vbOKOnly)
' Exit Function
'End If
'If mSMTPProfileName = vbNullString Then
' 'fnGENMessageBox("fnGENCon
nectDataba
se: An error has occurred during startup. Please provide an SMTP Profile Name for error processing.", vbCritical + vbOKOnly)
' Exit Function
'End If
'If mEmailSupportGroup = vbNullString Then
' 'fnGENMessageBox("fnGENCon
nectDataba
se: An error has occurred during startup. Please provide a valid Email support group.", vbCritical + vbOKOnly)
' Exit Function
'End If
' Create a new instance of our SQL Engine
'oCNN = New OleDb.OleDbConnection()
oCNN = New ADODB.Connection()
oCNN.ConnectionString = "Provider=OraOLEDB.Oracle;
" & _
"Data Source=" & mTNSName & ";" & _
"User ID=" & sUserID & ";" & _
"Password=" & sPassword & ";" & _
"PLSQLRSet=1;ChunkSize=655
35;"
'oCNN.ConnectionString = "Provider=sqloledb;" & _
' "Data Source=" & "(local)" & ";" & _
' "Initial Catalog=" & "SD" & ";" & _
' "User ID=" & sUserID & ";" & _
' "Password=" & sPassword & ";"
oCNN.Open()
If Not oCNN.State = System.Data.ConnectionStat
e.Open Then
'DO STUFF
End If
' Set that we have connected
bConnected = True
' Return that we have connected
fnGENConnectDatabase = S_OK
Exit Function
GoTo fnGENConnectDatabase_Exit
fnGENConnectDatabase_Clean
up:
oCMD = Nothing
oPRM = Nothing
oCNN = Nothing
GoTo fnGENConnectDatabase_Exit
fnGENConnectDatabase_Error
:
'fnGENMessageBox("fnGENCon
nectDataba
se: An error has occurred connecting to the database." & vbCrLf & "Oracle Error Code: " & Format(oCMD.Parameters("nE
rrorCode")
.Value) & vbCrLf & Err.Description, vbCritical + vbOKOnly)
fnGENConnectDatabase = S_FAILURE
GoTo fnGENConnectDatabase_Clean
up
fnGENConnectDatabase_Exit:
Exit Function
End Function
End Class
------------------END VB------------------------
------
------------------START ASP-----------------------
-------
<%@ Language=VBScript %>
<%
set oTestSDClass = Server.CreateObject("TestS
DClass.cls
TestSDClas
s")
response.Write ("instantiated........<br>
")
sTestString = "TestString"
iStrLength = oTestSDClass.fnTest(sTestS
tring)
response.Write ("length of """ & sTestString & """ is " & iStrLength & ".<br><p>") response.Write ("call done.<hr>")
'Try Connect
oTestSDClass.TNSNames = "YOURORACLESERVER"
oTestSDClass.Environment = 1
oTestSDClass.EmailSupportG
roup = "email@yourserver.com.au"
oTestSDClass.SMTPServerNam
e = "YOUREXCHANGESERVER"
oTestSDClass.SMTPProfileNa
me = "email@yourserver.com.au"
iResult = oTestSDClass.fnGENConnectD
atabase()
response.Write ("iResult: " & iResult)
%>
------------------END ASP-----------------------
-------