Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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 May 14th, 2012, 12:10 PM
Authorized User
 
Join Date: Dec 2007
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
Default Problem importing onlinediary in c#

I am trying to convert the vb code in the book to c#, and am trying to import the onlinediary with a using statement. Is there an alternate method? I have tried instantiating the class and referencing the object in the calls to the methods defined in the class. Same problem applies to the diaryentry and diaryevent classes.

Thanks for any help with this.


Tom
__________________
Thomas G Magaro
 
Old May 14th, 2012, 03:05 PM
Authorized User
 
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what exactly is d error msg?
__________________
busteronline
 
Old May 14th, 2012, 06:50 PM
Authorized User
 
Join Date: Dec 2007
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
Default

I'm not really sure.

I've tried running the debugger on it, but it the code executes fine, but I am getting the stack trace screen saying that a field count is being accessed after the reader is closed. Like I said, it is executing all the code fine.

By the way, this is happening right after I complete the login process.

Here is the code:

<code>
publicstaticSqlDataReader GetDiaryEventsByDate(
int diaryId, DateTime fromDate, DateTime toDate)
{
SqlConnection conn = newSqlConnection(
"data source=tommagaro-pc; initial catalog=diarydb; integrated security=true");
SqlCommand cmd = newSqlCommand("GetDaysWithEvents", conn);
cmd.CommandType =
CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@DiaryId", diaryId);
cmd.Parameters.AddWithValue(
"@EventFromDate", fromDate);
cmd.Parameters.AddWithValue(
"@EventToDate", toDate);
//cmd.Parameters.AddWithValue("@MaxRows", 0);
conn.Open();
SqlDataReader eventSQLDR = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Dispose();
conn.Close();
conn.Dispose();
return eventSQLDR;
}
</code>

It's when it finishes this code that it just jumps to the stack trace page.

Tom
__________________
Thomas G Magaro
 
Old May 15th, 2012, 02:22 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

A SqlDataReader needs an open connection in order to work successfully. In your code, you're closing the connection in the function that gets the reader. By the time the reader returns at the calling code the underlying connection is closed and the reader will fail. To fix this, don't close and dispose the connection object. The enum CommandBehavior.CloseConnection will automatically close the connection when it's done reading.

If you look at the original VB code you see it follows the same pattern in this function.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old May 15th, 2012, 03:38 PM
Authorized User
 
Join Date: Dec 2007
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Hey Imar,

Once again, thanks. However, I am still getting the error, and I think it is because of the temporary files that VWD produces during the compile process were still coming up in a find of the entire solution on the term dispose. Is there any way of deleting these files so that I can get a whole new build.

Tom
__________________
Thomas G Magaro
 
Old May 17th, 2012, 11:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

They should be recreated whenever you compile. You could try renaming the project and then opening it in VS; this should give you a clean folder. Alternatively, just delete the files from the folder that contains your temporary file.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query on OnlineDiary ! ostwald BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 8 July 15th, 2007 12:20 PM
Getting error in OnlineDiary application rsexton BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 June 4th, 2007 03:25 AM
Problem importing CSV hman MySQL 0 January 6th, 2007 09:13 AM
Server Error in '/OnlineDiary' Application. aaaboye BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 October 16th, 2006 03:29 PM
Problem importing dates IronStar MySQL 0 April 16th, 2005 05:32 PM





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