473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem when invoking stored procedure with cursor from inside .net

6
Dear all,

i'm facing a problem with my storedprocedure which happened when i ran my web application and reach to the point where my class invoke this storedprocedure,

my SP contains a cursor that built his sql according to certain condition, so i put the "SET @cur Cursor For....." inside the if block (definitely i've declared it under AS keyword directly) and this SP is working well inside sql server(I've tested it), BUT when my ASP.net code invoke this SP it gives me the following error :
"The Variable @cur does not currently have a cursor allocated to it" repeated as much as there are IF clauses in my SP,


Please Help.

Regards,
Oct 22 '07 #1
9 2012
Plater
7,872 Expert 4TB
it's of type "curser"? I don't think I've ever heard of that data type.
Is it used to "print output" or something?
Like a Stream would be used in .Net?
Oct 22 '07 #2
ookdeh
6
Cursor is a datatype used to store result for certain sql and then you can went through this result inside stored procedure ...
Oct 22 '07 #3
Plater
7,872 Expert 4TB
Hmm I guess I can only suggest you check "@cur is NOT null" first.
Maybe something else is going wrong beforehand and the @cur is not getting any results to be scanned?
Oct 22 '07 #4
ookdeh
6
Hello ,

Actually i think the main issue that asp.net can't see the @Cur variable when it is assigned inside an inner scope (the if statment scope) because this error message usually comes when the SP didn't see the "SET @Cur For " Statment and i didn't know why this comes from asp.net side although it is well from SP side.
Oct 24 '07 #5
Plater
7,872 Expert 4TB
How is your stored procedure created? I believe only parameters defined as being arguments to the stored procedure can be seen from the "outside"
Oct 24 '07 #6
ookdeh
6
Hello,

I've created the SP manually and not programaticly, And hereunder the SP ;

ALTER PROCEDURE SP_GetEngLogsIDPerStatus_Date_ForTrackEng_Page

(
@UID int ,
@Status nvarchar(10)='',
@isDR nvarchar(10)='',
@FD as datetime ='',
@TD as datetime ='',
@LogsIDs nvarchar(1000)='' output
)

AS
Set NoCount ON
Declare @MaxId int
Declare @EscId int
Declare @LogId int
declare @TempLIds nvarchar(1000)
set @tempLIds = ''
Declare @Cur cursor
Declare @sql nvarchar(300)



if @status = 'closed'

begin
print @status
if @isDR = 'True'
begin
print 'interval Req'
SET @Cur = cursor for
SELECT Escalation.LogCID, Escalation.EscID
FROM Escalation INNER JOIN
[Log-Call] ON Escalation.LogCID = [Log-Call].LogCID
WHERE (Escalation.UserID = @UID) AND ([Log-Call].LogCStatus = 'Closed')AND ([Log-Call].ClosedDate BETWEEN @FD AND DATEADD(d,1,@TD))

end

else if @isDR = 'False'
begin
SET @Cur = cursor for
SELECT Escalation.LogCID, Escalation.EscID
FROM Escalation INNER JOIN
[Log-Call] ON Escalation.LogCID = [Log-Call].LogCID
WHERE (Escalation.UserID = @UID) AND ([Log-Call].LogCStatus = 'Closed')

end
end

else if @status = 'open' or @status = 'pending'
begin
print @status
if @isDR = 'True'
begin
SET @Cur = cursor for
SELECT Escalation.LogCID, Escalation.EscID
FROM Escalation INNER JOIN
[Log-Call] ON Escalation.LogCID = [Log-Call].LogCID
WHERE (Escalation.UserID = @UID) AND ([Log-Call].LogCStatus = 'Open' OR
[Log-Call].LogCStatus = 'Pending') AND (Escalation.EscDate BETWEEN @FD AND DATEADD(d,1,@TD))


end

else if @isDR = 'False'
begin
SET @Cur = cursor for
SELECT Escalation.LogCID, Escalation.EscID
FROM Escalation INNER JOIN
[Log-Call] ON Escalation.LogCID = [Log-Call].LogCID
WHERE (Escalation.UserID = @UID) AND ([Log-Call].LogCStatus = 'Open' OR
[Log-Call].LogCStatus = 'Pending')

end
end






OPEN @cur
FETCH NEXT FROM @cur INTO @LogID,@EscID
WHILE @@FETCH_STATUS = 0
begin

select @MaxID=max(EscID) from Escalation where logcid = @logID

if @MaxID = @EscID
begin
SET @TempLIds = @TempLIds + ',' + LTrim(str(@logID))
End

FETCH NEXT FROM @cur INTO @LogID,@EscID
End

set @LogsIds = @TempLIds
print @LogsIDs


close @Cur
deallocate @cur
print 'Finaly -- ' + @TempLIds

If @@ERROR <> 0 GoTo ErrorHandler
Set NoCount OFF


ErrorHandler:
Return(@@ERROR)
Oct 25 '07 #7
Plater
7,872 Expert 4TB
These:
Expand|Select|Wrap|Line Numbers
  1. @UID int ,
  2. @Status nvarchar(10)='',
  3. @isDR nvarchar(10)='',
  4. @FD as datetime ='',
  5. @TD as datetime ='',
  6. @LogsIDs nvarchar(1000)='' output
  7.  
Along with:
Expand|Select|Wrap|Line Numbers
  1. RETURN_VALUE
  2.  
Are the only variables accessable outside of the procedure (the calling code), @CUR is not one of them, so you should not be able to get at it from the .NET side
Oct 25 '07 #8
ookdeh
6
first thank you Plater for your help,

actually i'm not accessing @cur from .Net side, the only thing i retreive value is "@LogsIDs" variable from .Net side ,this variable is been populated inside @cur iteration, and this which made me confused when .Net through the error message regarding the Cursor and i didn't called it anyware. i belive this error comes from SQL to .Net .
Oct 28 '07 #9
ookdeh
6
Hello,

actually i've created 4 seperated stored procedures to solve this issue and i have differntiate between thier calling from .net side and everything is OK.

Regards.
Nov 5 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to...
1
by: Steve Thorpe | last post by:
Hi. I have two sql servers and have ran exec sp_addlinkedserver 'ACSPSM', N'SQL Server' to link one to the other and also vise versa. Each server has two users permissioned. My problem is...
3
by: Jason Callas | last post by:
I have a stored procedure that runs as a step in a scheduled job. For some reason the job does not seem to finish when ran from the job but does fine when run from a window in SQL Query. I know...
4
by: R. Z. | last post by:
I 've have a stored procedure that compares fields across databases. In order to do so it requires 2 values it acquires from 2 tables. The search is based on the ID of the data owner and a subject:...
1
by: GAS | last post by:
I have tried to figure this out for a couple of days now and I'm not making much headway. I have a cursor that I can't get to work properly. There are two cursors in the stored procedure. The...
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
3
by: N. Shamsundar | last post by:
A stored procedure (listed below) that loads fine on Windows XP with DB2 V8.1.4 Express fails to load on Linux DB2 Workgroup server V8.1, with the following message: > sh-2.05a$ db2 -td@ -f...
4
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can...
7
by: rzagars | last post by:
I have just started working on DB2 which the syntax is a lot different. I am trying to create a SQL stored procedure for generating reports. I want to use temporary database which in this example...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.