 |
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
|
|
|
|

May 14th, 2012, 12:10 PM
|
Authorized User
|
|
Join Date: Dec 2007
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
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
|

May 14th, 2012, 03:05 PM
|
Authorized User
|
|
Join Date: Jul 2008
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
what exactly is d error msg?
__________________
busteronline
|

May 14th, 2012, 06:50 PM
|
Authorized User
|
|
Join Date: Dec 2007
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
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
|

May 15th, 2012, 02:22 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

May 15th, 2012, 03:38 PM
|
Authorized User
|
|
Join Date: Dec 2007
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
|
|
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
|

May 17th, 2012, 11:24 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |