Stored procedure problem update - help needed
am 19.01.2006 19:58:17 von rkirkwoodHello everyone,
I'm using the following procedure to do two functions.
1) Extract all zip codes from a database of American zip codes, which
falls within a 15 miles radius from a predefined zip code (variable
@zipcode) Then...
2) Compare the results to a zip code column in a customers table, for
matching records and provide a recorset including bsId and bsZipCode.
eg There are 2 sitters living within 15 miles of your zipcode area,
Which are bsID...
Now the procedure is working fine and returns the expected results as
long as the recordset has some records, but if the recordset has no
records (empty recordset) then I receive the following error message on
the webpage.
ERROR MESSAGE
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/Parents/Sign_up8.asp, line 41
Line 41 refers to this part of the code
....
' set the record count
Sitters15_2_total = Sitters15_2.RecordCount
Could anyone tell me what is causing this error? Do I need to add
something to the proc for error handling if the recordset is empty?
I'm very new to this and not the one who wrote the proc, so a full
explanation, or actual fix would be greatly appreciated.
FOLLOWING IS THE STORED PROCEDURE AS WELL AS THE ASP CODE CALLING THE
PROCEDURE ON MY PAGE.
I'M USING DREAMWEAVER - VBSCRIPT - SQL2000
Thanks, Robert
CREATE PROCEDURE dbo.psFindSitters15miles2
(@zipcode char(7))
AS
SET NOCOUNT ON
Declare @Result varchar(90)
Declare @lat decimal(9,6)
Declare @lng decimal(9,6)
Declare @Latitude decimal(9,6)
Declare @Longitude decimal(9,6)
set @Result = 'err';
--find the parent
if (@zipcode<>0) begin --find LAT and LNG
select @lat=[Latitude],@lng=[Longitude] FROM tbZip WHERE ZipCode =
@zipcode
--select @lat=[Latitude], @lng=[Longitude] FROM tbZip WHERE ZipCode =
90210
end;
if (@lat<> 0) begin --another query
SELECT bsID, bsZipCode FROM tbSitters WHERE bsZipCode in (SELECT
ZipCode FROM tbZip WHERE 15 > 3959 * ACOS(SIN(@Lat/57.3) *
SIN(Latitude/57.3) + COS(@Lat/57.3) * COS(Latitude/57.3) *
COS((Longitude/57.3) - (@Lng/57.3))) )
end;
GO
cODE CALLING THE PROCEDURE
<%
Dim Command1__zipcode
Command1__zipcode = "90210"
if(Request("zipcode") <> "") then Command1__zipcode =
Request("zipcode")
%>
<%
set Command1 = Server.CreateObject("ADODB.Command")
Command1.ActiveConnection = MM_Phoneababysitter_STRING
Command1.CommandText = "dbo.psFindSitters15miles2"
Command1.Parameters.Append Command1.CreateParameter("@RETURN_VALUE", 3,
4)
Command1.Parameters.Append Command1.CreateParameter("@zipcode", 129,
1,7,Command1__zipcode)
Command1.CommandType = 4
Command1.CommandTimeout = 0
Command1.Prepared = true
set Sitters15_2 = Command1.Execute
Sitters15_2_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
Sitters15_2_numRows = Sitters15_2_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats
variables
Dim Sitters15_2_total
Dim Sitters15_2_first
Dim Sitters15_2_last
' set the record count
Sitters15_2_total = Sitters15_2.RecordCount
' set the number of rows displayed on this page
If (Sitters15_2_numRows < 0) Then
Sitters15_2_numRows = Sitters15_2_total
Elseif (Sitters15_2_numRows = 0) Then
Sitters15_2_numRows = 1
End If
' set the first and last displayed record
Sitters15_2_first = 1
Sitters15_2_last = Sitters15_2_first + Sitters15_2_numRows - 1
' if we have the correct record count, check the other stats
If (Sitters15_2_total <> -1) Then
If (Sitters15_2_first > Sitters15_2_total) Then
Sitters15_2_first = Sitters15_2_total
End If
If (Sitters15_2_last > Sitters15_2_total) Then
Sitters15_2_last = Sitters15_2_total
End If
If (Sitters15_2_numRows > Sitters15_2_total) Then
Sitters15_2_numRows = Sitters15_2_total
End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually
count them
If (Sitters15_2_total = -1) Then
' count the total records by iterating through the recordset
Sitters15_2_total=0
While (Not Sitters15_2.EOF)
Sitters15_2_total = Sitters15_2_total + 1
Sitters15_2.MoveNext
Wend
' reset the cursor to the beginning
If (Sitters15_2.CursorType > 0) Then
Sitters15_2.MoveFirst
Else
Sitters15_2.Requery
End If
' set the number of rows displayed on this page
If (Sitters15_2_numRows < 0 Or Sitters15_2_numRows >
Sitters15_2_total) Then
Sitters15_2_numRows = Sitters15_2_total
End If
' set the first and last displayed record
Sitters15_2_first = 1
Sitters15_2_last = Sitters15_2_first + Sitters15_2_numRows - 1
If (Sitters15_2_first > Sitters15_2_total) Then
Sitters15_2_first = Sitters15_2_total
End If
If (Sitters15_2_last > Sitters15_2_total) Then
Sitters15_2_last = Sitters15_2_total
End If
End If
%>