Classic ASP - Disconnected Recordsets?

Soldato
Joined
18 Oct 2002
Posts
15,980
Location
The land of milk & beans
Hi all.

I'm currently trying to make myself a few classes and include files to standardise the work I do, and hopefully make things a bit neater too, but I'm having a few problems.

Here's an example

usefulfuncs.asp...
Code:
	' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= \/ \/ \/ \/ =-
	'	LoadRSFromDB															
	'		IN:		Object: ADO Connection; String: SQL statement
	'		OUT:	Disconnected recordset
	' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		function LoadRSFromDB(p_cn, byval p_SQL)
			dim p_rs

			if len(p_SQL & "") <= 0 then err.raise 1, "UsefulFuncs: LoadRSFromDB", "No SQL statement provided [UF003]"
			
			set p_rs = Server.CreateObject("ADODB.Recordset")			
			p_rs.Open p_SQL, p_cn, adOpenForwardOnly, adLockReadOnly

			' Error handler
			if err <> 0 then 
				err.raise err.number, "UsefulFuncs: LoadRSFromDB", err.Description & " [UF004]"
			end if

			' Disconnect the recordset
			set p_rs.ActiveConnection = nothing  
			
			' Return
			set LoadRSFromDB = p_rs
		end function
	' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /\ /\ /\ /\ =-

default.asp, includes usefulfuncs.asp
Code:
	set rsAdmin = LoadRSFromDB(cn, "SELECT * FROM Admin;")
	Response.Write(rsAdmin.Recordcount)

rsAdmin does not do anything at all, it does not contain a recordset, nor does it cause an error (even when used like response.write(rsAdmin.foobar)

Anyone know whats going on here?
 
Last edited:
gah! always the way - fixed minutes after sitting there for hours and then posting :)

if anyones interested, heres the function to return a disconnected recordset - i missed setting the cursorlocation to the client...

Code:
	' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= \/ \/ \/ \/ =-
	'	LoadRSFromDB															
	'		IN:	Object: ADO Connection; String: SQL statement
	'		OUT:	Disconnected recordset
	' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
		function LoadRSFromDB(p_cn, byval p_SQL)
			dim p_rs
			
			' Assertions - I don't know why it appears as a string, it just does
			if vartype(cn) <> vbString then err.raise 1, "UsefulFuncs: LoadRSFromDB", "Invalid connecion object provided [UF002]"
			if len(p_SQL & "") <= 0 then err.raise 1, "UsefulFuncs: LoadRSFromDB", "No SQL statement provided [UF003]"
			
			set p_rs = Server.CreateObject("ADODB.Recordset")	
			p_rs.CursorLocation = adUseClient		
			p_rs.Open p_SQL, p_cn, adOpenForwardOnly, adLockReadOnly

			' Error handler
			if err <> 0 then 
				err.raise err.number, "UsefulFuncs: LoadRSFromDB", err.Description & " [UF004]"
			end if

			' Disconnect the recordset
			set p_rs.ActiveConnection = nothing  
			
			' Return
			set LoadRSFromDB = p_rs
		end function
	' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= /\ /\ /\ /\ =-
 
Back
Top Bottom