473,785 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Sta rt(object sender, EventArgs e)
{
//Creating a global pooled connection object
ConnectionStrin gSettings DBconn =
ConfigurationMa nager.Connectio nStrings["MyDatabase "];
SAConnection _conn = new SAConnection(DB conn.Connection String);
Application.Loc k();
Application["DBConnecti on"] = (SAConnection)_ conn;
Application.UnL ock();
}

In the code behind of a web page I have:

protected void Page_Load(objec t sender, EventArgs e)
{
SAConnection _conn = (SAConnection)A pplication["DBConnecti on"];

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

try
{
_conn.Open();
command.Connect ion = _conn;
SADataReader reader =
command.Execute Reader(CommandB ehavior.CloseCo nnection);
MarkeDL.DataSou rce = reader;
MarkeDL.DataBin d();
}
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 1460
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_Sta rt(object sender, EventArgs e)
{
//Creating a global pooled connection object
ConnectionStrin gSettings DBconn =
ConfigurationMa nager.Connectio nStrings["MyDatabase "];
SAConnection _conn = new SAConnection(DB conn.Connection String);
Application.Loc k();
Application["DBConnecti on"] = (SAConnection)_ conn;
Application.UnL ock();
}

In the code behind of a web page I have:

protected void Page_Load(objec t sender, EventArgs e)
{
SAConnection _conn = (SAConnection)A pplication["DBConnecti on"];

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

try
{
_conn.Open();
command.Connect ion = _conn;
SADataReader reader =
command.Execute Reader(CommandB ehavior.CloseCo nnection);
MarkeDL.DataSou rce = reader;
MarkeDL.DataBin d();
}
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
1748
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 I find is that in the database we are currently creating the primary key within the stored procedure like so: Declare @LastValue int Set @LastValue = (Select ScreeningId from Support) set @LastValue = @LastValue + 1 Update Support Set...
5
14113
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 selected in DropDownListA. I am not trying to do anything fancy with AJAX, i am happy to use Post Backs. If it were two controls just on the page then i would simply specify a control parameter for the SelectCommand of the SQLDataSource control which...
2
1718
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 at runtime. In ASP 1.0 we could do this in code behind, but how do we do it in ASP 2.0? The examples I see are setting up controls compeletly at design time. Thanks, Charlie
2
8148
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 closes its connections, even if they are being idle for a long time. Is there some way to make the pool automatically release a connection if not being used for a certain period of time? I don't want to use the "Connection Lifetime" property of...
1
1670
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" Width="80px"/></td> If so what is the alternative.
7
1749
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 fields but display the decrypted data in the controls instead of the encrypted data. I also want to use a binding navigator to scroll through the records and to add/delete records. I don't have a problem with the encryption/decryption but am...
2
1610
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 after a page refresh (or in this case a window.location.replace(...))? I have an UpdateDB() ASP function. Can that be kicked off by an event when the user finishes typing into a asp:textbox, for example, so the data is saved before a refresh?
3
1355
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 me........ Thanx n regards............
0
2205
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 the web service, with a web reference to those datasets via exposed s on the web service. The client app has a series of windows forms designed to manage particular types of data. For example, there's a manage users form. On each of these...
0
9480
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,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 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...
1
10091
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,...
1
7499
isladogs
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...
0
6739
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();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.