Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 14th, 2012, 01:10 PM
Authorized User
Points: 222, Level: 4
Points: 222, Level: 4 Points: 222, Level: 4 Points: 222, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2007
Location: Phoenix, AZ, USA.
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
  #2 (permalink)  
Old May 14th, 2012, 04:05 PM
Authorized User
Points: 116, Level: 2
Points: 116, Level: 2 Points: 116, Level: 2 Points: 116, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2008
Location: SOMERSET, , USA.
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what exactly is d error msg?
__________________
busteronline
  #3 (permalink)  
Old May 14th, 2012, 07:50 PM
Authorized User
Points: 222, Level: 4
Points: 222, Level: 4 Points: 222, Level: 4 Points: 222, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2007
Location: Phoenix, AZ, USA.
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
  #4 (permalink)  
Old May 15th, 2012, 03:22 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 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!
  #5 (permalink)  
Old May 15th, 2012, 04:38 PM
Authorized User
Points: 222, Level: 4
Points: 222, Level: 4 Points: 222, Level: 4 Points: 222, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2007
Location: Phoenix, AZ, USA.
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
  #6 (permalink)  
Old May 17th, 2012, 12:24 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 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!
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01: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 04: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 04:29 PM
Problem importing dates IronStar MySQL 0 April 16th, 2005 06:32 PM



All times are GMT -4. The time now is 05:10 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.