473,385 Members | 1,712 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,385 software developers and data experts.

ASP.NET Databound controls and connection pools --> How does it work?

Tom
I try to do the following:

Generate a pooled connection in a web application. I use the following code:

In my Global.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
//Creating a global pooled connection object
ConnectionStringSettings DBconn =
ConfigurationManager.ConnectionStrings["MyDatabase"];
SAConnection _conn = new SAConnection(DBconn.ConnectionString);
Application.Lock();
Application["DBConnection"] = (SAConnection)_conn;
Application.UnLock();
}

In the code behind of a web page I have:

protected void Page_Load(object sender, EventArgs e)
{
SAConnection _conn = (SAConnection)Application["DBConnection"];

string commandString = "Select * from MarkenAm";
SACommand command = new SACommand(commandString);

try
{
_conn.Open();
command.Connection = _conn;
SADataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnect ion);
MarkeDL.DataSource = reader;
MarkeDL.DataBind();
}
finally
{
_conn.Close();
}
}

This works fine but I have to write all the code manually. Is there any
way to tell the designer about my connection pool stored in the
application scope of my web app?? I like to use the click an point
programming feature of the designer, but want all my web pages to use
the same centrally defined connection pool. Is this possible and if so how?

(I wrote tons of web apps in Java, but I am new to ASP.NET)

Thanks for your help

Thomas
Sep 12 '07 #1
2 1441
you've coded such that no pooling is effectively used, as you are using
the same connection for all requests. also as you do not lock the
connection during use (by sqlcommands), two page requests that try to
use the connection at the same time will fail.

you should only keep the connection string in application, and create a
connection for each request. this will enable pooling to be be used by
every request.
-- bruce (sqlwork.com)

Tom wrote:
I try to do the following:

Generate a pooled connection in a web application. I use the following
code:

In my Global.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
//Creating a global pooled connection object
ConnectionStringSettings DBconn =
ConfigurationManager.ConnectionStrings["MyDatabase"];
SAConnection _conn = new SAConnection(DBconn.ConnectionString);
Application.Lock();
Application["DBConnection"] = (SAConnection)_conn;
Application.UnLock();
}

In the code behind of a web page I have:

protected void Page_Load(object sender, EventArgs e)
{
SAConnection _conn = (SAConnection)Application["DBConnection"];

string commandString = "Select * from MarkenAm";
SACommand command = new SACommand(commandString);

try
{
_conn.Open();
command.Connection = _conn;
SADataReader reader =
command.ExecuteReader(CommandBehavior.CloseConnect ion);
MarkeDL.DataSource = reader;
MarkeDL.DataBind();
}
finally
{
_conn.Close();
}
}

This works fine but I have to write all the code manually. Is there any
way to tell the designer about my connection pool stored in the
application scope of my web app?? I like to use the click an point
programming feature of the designer, but want all my web pages to use
the same centrally defined connection pool. Is this possible and if so how?

(I wrote tons of web apps in Java, but I am new to ASP.NET)

Thanks for your help

Thomas
Sep 12 '07 #2
Tom
Thanks for that input bruce. So does this mean, that ASP is managing the
pool in the background transparently? In J2EE you have to configure
connection pools in the container (application server) for every
application.

I hope ASP connection pools are also on application context and not on
page context!

Tom
bruce barker schrieb:
you've coded such that no pooling is effectively used, as you are using
the same connection for all requests. also as you do not lock the
connection during use (by sqlcommands), two page requests that try to
use the connection at the same time will fail.

you should only keep the connection string in application, and create a
connection for each request. this will enable pooling to be be used by
every request.
-- bruce (sqlwork.com)
Sep 13 '07 #3

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

Similar topics

6
by: Michael | last post by:
Hi Everyone, I'm currently using VS 2005 and would like to use the databinding of the controls to help ease up some of the coding I have to do (some of my forms have over 120 fields). The problem...
5
by: clickon | last post by:
This is driving me nuts, it is such a simply thing to do but i cannot for the life of me work out how you are suposed to do it. I want to update the data in DropDownListB based on what is...
2
by: Charlie | last post by:
Hi: The new databound controls (GridView, DetailsView, ect.) use declaritive syntax (i.e, setup in HTML at design time). However, at times sql statements and parameters may need to be derived...
2
by: Gen | last post by:
Hello there, I am developing a web application using Firebird.NET provider ver 1.7 Connection pooling is being used to better the application's performance. The problem is that the pool never...
1
by: Newish | last post by:
Hi Is it really not recommended to us Eval in databound controls as follows: <td><asp:TextBox id="BookTitle" Runat="Server" Text='<%# Eval("BookTitle") %>' Font-Size="8pt"...
7
by: =?Utf-8?B?aWxy?= | last post by:
Hi I have a table in an sql database that contains data that has been encrypted using the DPAPI. What I am trying to achieve is to bind several controls on a vb 2005 windows form to those...
2
by: Dave | last post by:
I only do ASP part time so this is a beginner question. I will attempt to make this a starightforward question... Is there any technique to keep values a user types into databound controls...
3
by: jith87 | last post by:
Can u tell me how to create connection pools in JDBC ???? Ths type of creating is said to have reduced the processing time spent during connecting and disconnecting to the databases. Pls help...
0
by: morathm | last post by:
I have a windows client database management application written in C# that connects to remote web services to do all the heavy work. The thin-client app uses strong typed datasets, all maintained at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

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.