Hi!
The situation is:
1. In Page_Load, I open a database connection which is closed on handler
finish.
2. In Button_Click, I do same thing again as above.
So during one request, a db connection opens/closes 2 times. I think this is
not normally
and now I added to my page class a 'private SqlConnection MyConn'. Both
above 2 handlers
check whether this field is null and creates/opens the connection. Am I
doing right?
This is a standard technique of ASP.NET for such situations?
Also, what event occurs early, Page_Load or Button_Click?
Thanks! 3 1088
Actually, you're probably better off doing it the first way you
describe. Database connections work best if you open and close them in
a single block of code. Ideally, wrapped in a using(){} block.
If you try to manage a private connection, you run the risk of leaving
it open or referenced by something that stays alive longer that you
expected. This leads to leaky code (which is still very possible in
C#), which will cause you much more trouble than the occasional page
opening and closing two connections to the database.
Good luck!
Jason Kester
Expat Software Consulting Services http://www.expatsoftware.com/
After debugging my first ASP.NET app, I found
that Page.Load event occurs before Button_Click and
Page.Unload raised at the end. So I placed a connection
close code within Unload. But can I be sure that Page.Unload
will be called in any situation?
"jasonkeste r" <ja*********@gm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . Actually, you're probably better off doing it the first way you describe. Database connections work best if you open and close them in a single block of code. Ideally, wrapped in a using(){} block.
If you try to manage a private connection, you run the risk of leaving it open or referenced by something that stays alive longer that you expected. This leads to leaky code (which is still very possible in C#), which will cause you much more trouble than the occasional page opening and closing two connections to the database.
Good luck!
Jason Kester Expat Software Consulting Services http://www.expatsoftware.com/
In theory.
All I can tell you is that I've spent loads of time tracking down
ConnectionPool exceptions in other people's code. There's a dozen ways
for your connections to get left open if you're not on top of them. In
a web app that you expect to have running for weeks at a time, they'll
pile up on you and you'll start seeing strange exceptions.
In my code, database connections and transactions always live in a
using block, and open/close statements are always within a few lines of
eachother. I've never had any leaks from this practice.
Jason Kester
Expat Software Consulting Services http://www.expatsoftware.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Luc Tremblay |
last post by:
Given the typical following code:
void Listener::HandleEvent(const Event& event)
{
// handling code
}
In a "clean" fashion, how is it possible to add custom data (to be
subsequently accessed) to the Event instance? By custom data i mean
practically anything, from a class to a single int. Particularly to my case,
|
by: Wim Hoogenraad |
last post by:
Dear Webprofessional,
In this newsletter we like to inform you about some developments on our
website.
First of all we would like to thank you who joined WebmastersLookup. Without
the Usenet community the service would not have grown so fast. The
membership is still open and it's for free. In the past few weeks we've been
|
by: Tom L |
last post by:
I'm pretty new to .net stuff, but not new to programming (lots of vb, sql,
cold fusion, and some asp)..
I have a "middle layer" object model I created, that has all my business
rules and database access for an order entry system, starting with the Order
object, and other basic child items, like LineItems and PAyments under that.
This is being used in the vb.net front-end for normal users in the company,
but I'd like to use this for the web...
|
by: Mr Newbie |
last post by:
I'm testing error handling configurations and having some trouble. I created
a WebForm called. ErrDefault.aspx and I am trying to use the Page error
attribute to force the redirection to a custom page, but I only get and
unhandled exception page and it does not direct me to my specific page. I'm
probably doing something really stupid, but I cant see what .
Any Ideas ? - Thanx Mr N
--------- DETAILS BELOW -----------
|
by: Adam J Knight |
last post by:
Hi all,
I am in the process of creating a custom membership provider (ASP.NET 2.0):
Currently I am inheriting from MembershipProvider which isn't a problem.
However, the membership.CreateUser() methods signature doesn't seem
relevant to my implementation.
For example, i will be needing to store a users address details and not just
| |
by: Jamey Shuemaker |
last post by:
I'm in the process of expanding my knowledge and use of Class Modules.
I've perused MSDN and this and other sites, and I'm pretty comfortable
with my understanding of Class Modules with the exception of custom
Collection Classes.
Background: I'm developing an A2K .mdb to be deployed as an .mde at my
current job-site. It has several custom controls which utilize custom
classes to wrap built-in controls, and add additional functionality....
|
by: Ben R. |
last post by:
My website uses a custome membership and role provider. I can use a custom
login control and user creation control and can debug my providers while
doing so with breakpoints. However, when I launch the asp.net website config
tool and go to the security tab, I get a polished screen with the error
message:
The object refererence is not set to an instance of an object
But despite putting breakpoints everywhere in both the roleprovider and...
|
by: Jakob Lithner |
last post by:
When I started a new ASP project I was eager to use the login facilities
offered in Framework 2.0/VS 2005.
I wanted:
- A custom principal that could hold my integer UserID from the database
- An easy way to classify different pages as either Admin, Member or Public,
where login is necessary for Admin and Member but not for Public. My idea was
to put the pages in different directories to easily keep my order.
- An easy menu system that...
|
by: Tim |
last post by:
have a 1.1 framework site that is being converted to 2.0.
I have a custom class MyPage that I'm trying to have all of my .Net
pages inherit.
My site uses both classic and .Net sessions so I am using the
MSDN.SessionPage to handle the sessions.
|
by: Ravi Kumar |
last post by:
hi :)
I was trying to develop a custom mod_python based web-site, just
today. the problem I got
though i liked the mod_python's feature of mapping and calling
functions in python script by parsing the url.
I mean, http://localhost/site/member/list?no=100
would call site/member.py page's function list with arguments no=100.
Thats a feature i liked.
But PROBLEM 01:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |