Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2006, 09:36 AM
Authorized User
 
Join Date: Dec 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default There is already an open DataReader associated wit

 Hi,
i have an outer loop using Datareader to get PeriodEndingDate.
After reading each record, i need to run a stored Procedure based on the data i got it.
I use the same connection for this.
When it reaches the Stored Procedure, it is giving error
There is already an open DataReader associated with this Connection which must be closed first.
How can i fix it?Do i really need to make another connection?
Thanks in advance
Jenni.


objConn.Open() ‘SqlConnection
        sql = "Select PeriodEndingDate from PayPeriods where (PeriodEndingDate >= DATEADD(day, - 90,'2/5/2006' )) "

        cmdSelect = New SqlCommand(sql, objConn)
        dtrPayroll = cmdSelect.ExecuteReader

        While dtrPayroll.Read
                  PeriodEndingDate = dtrPayroll("PeriodEndingDate")
                StartWorkDate = DateValue(DateAdd(DateInterval.Day, -6, CType(PeriodEndingDate, Date)))
                EndWorkDate = DateValue(DateAdd(DateInterval.DayOfYear, 0, CType(PeriodEndingDate, Date)))

                'Execute Stored Procedure
                cmdPostTime = New SqlCommand("Sp_CalcPayPeriod", objConn)
                cmdPostTime.CommandType = CommandType.StoredProcedure
                'cmdPostTime.CommandTimeout = 180 ' 3 mints
                cmdPostTime.Parameters.Add("@FromDate", StartWorkDate)
                cmdPostTime.Parameters.Add("@ToDate", EndWorkDate)
                cmdPostTime.ExecuteNonQuery()


        End While
        dtrPayroll.Close()
        objConn.Close()




 
Old July 2nd, 2006, 01:10 PM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
    Unfortunately if you open a DataReader in a connection ADO.NET won't allow you to use the same connection for executing any other command or SP.

There are two solutions here
1) Use a different connection object to call SP
2) Use DataTable instead of DataReader to loop through the object and call the SP using the connection object.

It is not how much we do,
but how much love we put in the doing.

-Mother Theresa





Similar Threads
Thread Thread Starter Forum Replies Last Post
There is already an open datareader associated wit yasinirshad ADO.NET 1 August 12th, 2007 03:37 AM
Problem wit struts and spring DR POMPEII Struts 0 August 17th, 2006 09:16 AM
Datareader NitinJoshi ADO.NET 4 January 31st, 2005 08:34 AM
There is already an open DataReader associated wit flyin ADO.NET 14 February 20th, 2004 08:41 AM
"There is already an open DataReader " error kaz VS.NET 2002/2003 4 December 17th, 2003 11:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.