473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to use one database connection object per page request

Hi all,

I am creating a website in which in an Item detail page there are a number
of web controls (7 or 8) and what is happening that inside each of control's
Page_Load() function I am creating a database object to query data from
database (using MySQL database). So it means that for each page request I am
using 7 or 8 database connection which is something quite bad as far as
performance is concerned. So please tell me how can change my design to use
only one database connection object per page request? Important thing is I
need to close database connection also once page request is fulfil and if I
dont close database connection then database connection is still there for a
very long time and it could cause bottleneck at my database server for more
new connections.

Thanks,

Arsalan

May 20 '06 #1
6 3422
as each control is loaded, it will open, run, then close the connection. There should be no problem so long as each has the
open/close statements in the code.


"Arsalan Ahmad" <ar*****@hotmail.com> wrote in message news:eC**************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am creating a website in which in an Item detail page there are a number of web controls (7 or 8) and what is happening that
inside each of control's Page_Load() function I am creating a database object to query data from database (using MySQL database).
So it means that for each page request I am using 7 or 8 database connection which is something quite bad as far as performance is
concerned. So please tell me how can change my design to use only one database connection object per page request? Important thing
is I need to close database connection also once page request is fulfil and if I dont close database connection then database
connection is still there for a very long time and it could cause bottleneck at my database server for more new connections.

Thanks,

Arsalan

May 20 '06 #2
This good be total off but http://www.asp.net/guidedtour2/s11.aspx

I am new, but i happen to come across the link.

May 20 '06 #3
Arsalan Ahmad wrote:
Hi all,

I am creating a website in which in an Item detail page there are a number
of web controls (7 or 8) and what is happening that inside each of control's
Page_Load() function I am creating a database object to query data from
database (using MySQL database). So it means that for each page request I am
using 7 or 8 database connection which is something quite bad as far as
performance is concerned. So please tell me how can change my design to use
only one database connection object per page request? Important thing is I
need to close database connection also once page request is fulfil and if I
dont close database connection then database connection is still there for a
very long time and it could cause bottleneck at my database server for more
new connections.

Thanks,

Arsalan


Which data provider are you using? The OleDbConnection and
OdbcConnection classes both support connection pooling, so if you're
using either of them, it shouldn't be an issue to follow the "open a
connection, do a command, close the connection" model. It looks like
you'll use a lot of connections, but behind the scenes the connection
pool will manage it for you.

Damien

May 21 '06 #4
Hi,

I am using MySQL .NET Connector and I am afraid that it does not support
connection pooling and that is why I think that opening a new connection by
each control in a page request will make it quite slow.

Regards,

Arsalan

"Damien" <Da*******************@hotmail.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Arsalan Ahmad wrote:
Hi all,

I am creating a website in which in an Item detail page there are a
number
of web controls (7 or 8) and what is happening that inside each of
control's
Page_Load() function I am creating a database object to query data from
database (using MySQL database). So it means that for each page request I
am
using 7 or 8 database connection which is something quite bad as far as
performance is concerned. So please tell me how can change my design to
use
only one database connection object per page request? Important thing is
I
need to close database connection also once page request is fulfil and if
I
dont close database connection then database connection is still there
for a
very long time and it could cause bottleneck at my database server for
more
new connections.

Thanks,

Arsalan


Which data provider are you using? The OleDbConnection and
OdbcConnection classes both support connection pooling, so if you're
using either of them, it shouldn't be an issue to follow the "open a
connection, do a command, close the connection" model. It looks like
you'll use a lot of connections, but behind the scenes the connection
pool will manage it for you.

Damien

May 21 '06 #5
On Sun, 21 May 2006 20:22:23 +0200, "Arsalan Ahmad"
<ar*****@hotmail.com> wrote:
Hi,

I am using MySQL .NET Connector and I am afraid that it does not support
connection pooling and that is why I think that opening a new connection by
each control in a page request will make it quite slow.

Regards,

Arsalan

"Damien" <Da*******************@hotmail.com> wrote in message
news:11**********************@38g2000cwa.googlegr oups.com...
Arsalan Ahmad wrote:
Hi all,

I am creating a website in which in an Item detail page there are a
number
of web controls (7 or 8) and what is happening that inside each of
control's
Page_Load() function I am creating a database object to query data from
database (using MySQL database). So it means that for each page request I
am
using 7 or 8 database connection which is something quite bad as far as
performance is concerned. So please tell me how can change my design to
use
only one database connection object per page request? Important thing is
I
need to close database connection also once page request is fulfil and if
I
dont close database connection then database connection is still there
for a
very long time and it could cause bottleneck at my database server for
more
new connections.

Thanks,

Arsalan


Which data provider are you using? The OleDbConnection and
OdbcConnection classes both support connection pooling, so if you're
using either of them, it shouldn't be an issue to follow the "open a
connection, do a command, close the connection" model. It looks like
you'll use a lot of connections, but behind the scenes the connection
pool will manage it for you.

Damien


My understanding is that if you put connectionpooling in your connect
string to mysql, independent of the driver in .net, you will get
connection pooling to the database. Let me know if this is wrong, but
I don't think so.
Peter Kellner
http://peterkellner.net
May 21 '06 #6
Arsalan Ahmad wrote:
Hi,

I am using MySQL .NET Connector and I am afraid that it does not support
connection pooling and that is why I think that opening a new connection by
each control in a page request will make it quite slow.

Regards,

Arsalan
In that case, I would suggest (if you want to do one connection per
request), to create a base page which in an early event (say in the
Init event), opens a connection and puts it into
HttpContext.Current.Items, and which closes it in the Unload event.
Then everything that needs a connection in between will retrieve it
from the Items connection.

However, I wouldn't expect this to scale well. You may be better suited
to roll your own connection pool (assuming that your connection string
is always the same, this may not be too onerous), assuming that your
individual operations are independent.

Damien
"Damien" <Da*******************@hotmail.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
Arsalan Ahmad wrote:
Hi all,

I am creating a website in which in an Item detail page there are a
number
of web controls (7 or 8) and what is happening that inside each of
control's
Page_Load() function I am creating a database object to query data from
database (using MySQL database). So it means that for each page request I
am
using 7 or 8 database connection which is something quite bad as far as
performance is concerned. So please tell me how can change my design to
use
only one database connection object per page request? Important thing is
I
need to close database connection also once page request is fulfil and if
I
dont close database connection then database connection is still there
for a
very long time and it could cause bottleneck at my database server for
more
new connections.

Thanks,

Arsalan


Which data provider are you using? The OleDbConnection and
OdbcConnection classes both support connection pooling, so if you're
using either of them, it shouldn't be an issue to follow the "open a
connection, do a command, close the connection" model. It looks like
you'll use a lot of connections, but behind the scenes the connection
pool will manage it for you.

Damien


May 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben M. | last post by:
Greetings all, This should be an easy task, and Im sure it is, but as many times as I have tried, I cant seem to get this to work properly. We changed ISPs recently from a shared host to a...
4
by: Jim in Arizona | last post by:
I'm wanting to do a simple controlled voting page. I too our webserver off anonymous and everyone who accesses the website is a domain authenticated user. I've already done some control structure...
3
by: William | last post by:
Hi I have an ASP.NET application that connects to an Access database. Everything works fine except for the Session object. Data in the session object is lost after I've made a call to the...
1
by: Rico | last post by:
I have tried to access a database using asp.net. after some entries like 120+, I got an unspecified error message. Anyone know what is happening, it seems to be stuck at the same line even when i...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
2
daJunkCollector
by: daJunkCollector | last post by:
Hey, I am having a user fill out a form then the fields are going to uploaded to my database. So, at this point, when the user hits the submit button I want three things to happen: 1. The form...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
4
by: coldpizza | last post by:
Hi, I want to run a database query and then display the first 10 records on a web page. Then I want to be able to click the 'Next' link on the page to show the next 10 records, and so on. My...
3
eboschi
by: eboschi | last post by:
Hi all, i'm new to .net programming and i have some problems with database connection. I have written two web application. Both of them use ADODB Connection to Sql Server 2000 database. The problem...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.