Link to home
Start Free TrialLog in
Avatar of FireW0lf
FireW0lf

asked on

Problems using Provider=OraOLEDB.Oracle via VBScript/Classic ASP

Okay, background: existing Oracle db running on linux. I've taken over the creds for it.

I am looking to develop some basic (classic) asp pages to show some reporting info for Management, and seem to have hit a snag...

So far:
Installed SQL Developer. All test SQL queries work and provide the expected response!
At this stage using my local machine as dev, so installed the relevant 64 bit tools and drivers from the Universal installer.
Looking in ODBC (just to check), I have 64 bit "Oracle in OraClient 11g_home1".

Test 1:
SQL Developer
SELECT STAFFID, STAFFNAME FROM T_STAFFINFO WHERE STAFFNAME IS NOT NULL ORDER BY STAFFNAME asc;

Open in new window

Works perfectly

VBScript
Option Explicit

Dim isDebug, asp
isDebug = True
asp = 0

Dim strSQLQuery
strSQLQuery = "SELECT STAFFID, STAFFNAME FROM T_STAFFINFO WHERE STAFFNAME IS NOT NULL ORDER BY STAFFNAME asc"

Dim strDBDesc
strDBDesc = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=1.2.3.4)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=mySVC)));"

Dim strUserID: strUserID = "myUser"
Dim strPassword: strPassword = "myPass"

Dim ADODBConnection
Set ADODBConnection = CreateObject("ADODB.Connection")

Dim ADODBRS
Set ADODBRS = CreateObject("ADODB.Recordset")

Dim strConnection
strConnection = "Provider=OraOLEDB.Oracle;Data Source=" & strDBDesc & _
                "User ID=" & strUserID & ";Password=" & strPassword & ";"

DebugOut "strConnection = " & strConnection & vbCrLf

ADODBConnection.Open strConnection
Set ADODBRS = ADODBConnection.Execute(strSQLQuery)
Set ADODBConnection = Nothing

If Err <> 0 Then
    DebugOut "An error occurred in Opening Connection: " & Err.Number & " " & Err.Description & " " & Err.Source
Else
	
	ADODBRS.MoveFirst
	Do Until ADODBRS.EOF
	
	DebugOut ADODBRS("STAFFID") & vbTab & ADODBRS("STAFFNAME")
	ADODBRS.MoveNext
	
	Loop
End If


Sub DebugOut(sText)
	If IsDebug Then
		If asp=1 Then
			Response.Write Now() & vbTab & sText
		Else
			WScript.Echo Now() & vbTab & sText
		End If
	End If
End Sub

Open in new window

Also works perfectly. Rejigged that to classic .asp and put it behind IIS7.5 - works peachy as the first page, a drop down with all staff populated

Test 2
SQL Developer
SELECT to_char(ACTBEGIN, 'DD-MON-YYYY') as WORKDATE,
MIN(to_char(ACTBEGIN, 'HH24:MI:SS')) AS STARTTIME,
MAX(to_char(ACTEND, 'HH24:MI:SS')) AS FINISHTIME
FROM T_ATTENDANCE
WHERE STAFFID = 1
AND ACTBEGIN BETWEEN '01-OCT-16' AND ADD_MONTHS('01-OCT-16', 1)
GROUP BY to_char(ACTBEGIN, 'DD-MON-YYYY')
ORDER BY WORKDATE;

Open in new window

Works just fine

VBScript
Option Explicit

Dim isDebug, asp
isDebug = True
asp = 0

Dim strSQLQuery
strSQLQuery = "" & _
"SELECT to_char(ACTBEGIN, 'DD-MON-YYYY') as WORKDATE, " & _
"MIN(to_char(ACTBEGIN, 'HH24:MI:SS')) AS STARTTIME, " & _
"MAX(to_char(ACTEND, 'HH24:MI:SS')) AS FINISHTIME " & _
"FROM T_ATTENDANCE " & _
"WHERE STAFFID = 1 " & _
AND ACTBEGIN BETWEEN '%SDATE' AND ADD_MONTHS('%SDATE', 1) " & _
"GROUP BY to_char(ACTBEGIN, 'DD-MON-YYYY') " & _
"ORDER BY WORKDATE"

Dim strDBDesc
strDBDesc = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=1.2.3.4)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=mySVC)));"

Dim strUserID: strUserID = "myUser"
Dim strPassword: strPassword = "myPass"

Dim ADODBConnection
Set ADODBConnection = CreateObject("ADODB.Connection")

Dim ADODBRS
Set ADODBRS = CreateObject("ADODB.Recordset")

Dim strConnection
strConnection = "Provider=OraOLEDB.Oracle;Data Source=" & strDBDesc & _
                "User ID=" & strUserID & ";Password=" & strPassword & ";"
				
DebugOut strConnection & vbCrLf
DebugOut strSQLQuery
				
ADODBConnection.Open strConnection
Set ADODBRS = ADODBConnection.Execute(strSQLQuery)
Set ADODBConnection = Nothing

If Err <> 0 Then
    DebugOut "An error occurred in Opening Connection: " & Err.Number & " " & Err.Description & " " & Err.Source
End If

	'ADODBRS.MoveFirst
	Do Until ADODBRS.EOF
		DebugOut ADODBRS("WORKDATE") & vbTab & _
		ADODBRS("STARTTIME") & vbTab & _
		ADODBRS("FINISHTIME") & vbCrLf
		ADODBRS.MoveNext
	Loop


Sub DebugOut(sText)
	If IsDebug Then
		If asp=1 Then
			Response.Write Now() & vbTab & sText
		Else
			WScript.Echo Now() & vbTab & sText
		End If
	End If
End Sub

Open in new window

I get no output (apart from the test lines). If I uncomment out the ADODBRS.MoveFirst I get the dreaded ADODB.Recordset: Either BOF or EOF is True, or the current record has been deleted

So......
SQL Developer the SQL works fine
VBScript/Classic ASP a simple SQL query using the standard ADODB methods works fine
A more complex SQL query which works fine in SQL Developer returns no data when ran in VBScript using exactly the same connection strings as in the simple query

What am I doing wrong?????

I'll give 500 points to whoever fixes me
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FireW0lf
FireW0lf

ASKER

At this stage hard coding the dates in, for testing. Once it works they'll also be fed in from the first part of the webpage.

Okay, if that's good practice (sorry, I'm used to SQL Server) I'll do that.
But I don't see the hard-coded dates:
AND ACTBEGIN BETWEEN '%SDATE' AND ADD_MONTHS('%SDATE', 1) " 

It's been many years since I messed with classic ASP but I don't remember that being the correct syntax for a web page variable.

You should also use Bind Variables.
Yeah sorry, I was obfuscating and trying to keep the pasted code simple. Yes I use a simple Replace() routine to insert the date and the staff identifier. I'm using the classic ASP to handle any variables to keep the SQL works as simple as possible

You Sir are a legend, Have some points, as you nailed it!
Thank you very much, saved me a big headache