Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix 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 November 29th, 2013, 05:21 AM
Registered User
 
Join Date: Nov 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Database handling

I really enjoyed your book.

But there are two questions which accompanied me all the time when I studied the chapters with database access:

Shouldn't I close a database connection after having accessed database?
Doesn't it lead to too many open connections (and memory leaks) when I do not use something like "db.Close();" at the end of my code?



Thanks in advance for your brief feedback
 
Old December 4th, 2013, 06:46 PM
Wrox Author
 
Join Date: Dec 2011
Posts: 57
Thanks: 1
Thanked 19 Times in 19 Posts
Default

Hi,

Thanks for your comments about the book.

If you use the Database.Open method, the Web Pages framework calls the Close method at the end of the request. If you use ADO.NET code, you are always advised to create connections in a using block or to ensure that you call Close when you are done.

There is nothing stopping you from calling Database.Open in a using block. It's just that it is not necessary to do so.

There is a slightly different issue when it comes to SQL Compact. That particular database runs in the same process as the ASP.NET app, so you don't have to worry about unmanaged resources draining memory like connections to out-of-process resources (SQL Server, Access, MySQL etc) would.
The Following User Says Thank You to Mike Brind For This Useful Post:
Temp3D (December 6th, 2013)
 
Old December 6th, 2013, 04:36 AM
Registered User
 
Join Date: Nov 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Mike,

Thanks for your feedback.

Please allow me to ask for one more advice:

I'm also eagerly reading your articles / tutorials on mikesdotnetting.com and found your tutorial about integration of Entity Framework with ASP.NET Web Pages.

In fact, I've tried many different frameworks and languages and were very happy with ORM tools. However, I've made a little benchmark test based on SQL CE database and learned much to my surprise that access via Database helper is essentially faster than access via EF.

My results:

Write operations, each 1000 datasets

Entity Framework with Web Pages (SQL CE) [in ms]
EF test1: 2440 - 4623 - 6662
EF test2: 2609 - 4491 - 6621
EF test3: 2392 - 4725 - 7007
---------------------------------------------
SQL(Database.Open) with Web Pages (SQL CE) [in ms]
DB test1: 136 - 152 - 162
DB test2: 151 - 161 - 142
DB test3: 160 - 167 - 177

Read Operations, each 10000 datasets [in ms]

EF: 192 - 238 - 228
------------------------------
DB: 79 - 84 - 80 [normal Database method]
------------------------------
DBs: 121 - 94 - 100 [StronglyTyped from Jeremy Skinner]

Do you think that this performance difference could be realistic? I would really like to show the code of the test but I deleted it by mistake.

Many people think that such tests are not very meaningful based on "real" apps/websites. What do you think? And what method do you prefer: Database helper, EF or raw ADO.NET?

Sorry for so many nerving questions

Regards from Germany
Marcus


Quote:
Originally Posted by Mike Brind View Post
Hi,

Thanks for your comments about the book.

If you use the Database.Open method, the Web Pages framework calls the Close method at the end of the request. If you use ADO.NET code, you are always advised to create connections in a using block or to ensure that you call Close when you are done.

There is nothing stopping you from calling Database.Open in a using block. It's just that it is not necessary to do so.

There is a slightly different issue when it comes to SQL Compact. That particular database runs in the same process as the ASP.NET app, so you don't have to worry about unmanaged resources draining memory like connections to out-of-process resources (SQL Server, Access, MySQL etc) would.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Even Handling smfarooq C# 2 December 23rd, 2010 11:54 AM
About the Database Handling UmeshA BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 August 26th, 2009 12:15 PM
Is it possible to handling the database in Javascr pushpa Classic ASP Basics 3 March 9th, 2007 07:11 AM
FILE HANDLING yojeiram_n1 C++ Programming 2 March 13th, 2006 02:57 PM
Handling Datetime in database ksrmramu Classic ASP Databases 1 November 25th, 2005 05:42 AM





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